def main():
    network_config, template = get_network_config()

    elb_listeners_config = [
        ElbListenersConfig(instance_port='80',
                           loadbalancer_port='80',
                           loadbalancer_protocol='HTTP',
                           instance_protocol='HTTP',
                           sticky_app_cookie='JSESSION'),
        ElbListenersConfig(instance_port='8080',
                           loadbalancer_port='8080',
                           loadbalancer_protocol='HTTP',
                           instance_protocol='HTTP',
                           sticky_app_cookie='SESSIONTOKEN')
    ]

    elb_config1 = ElbConfig(elb_listeners_config=elb_listeners_config,
                            elb_health_check='HTTP:80/index.html',
                            elb_log_bucket='my-s3-bucket',
                            public_unit=False,
                            ssl_certificate_id=None,
                            healthy_threshold=10,
                            unhealthy_threshold=2,
                            interval=300,
                            timeout=30)
    elb_config2 = ElbConfig(elb_listeners_config=elb_listeners_config,
                            elb_health_check='HTTP:80/index.html',
                            elb_log_bucket='my-s3-bucket',
                            public_unit=True,
                            ssl_certificate_id='arn:aws:acm::tester',
                            healthy_threshold=10,
                            unhealthy_threshold=2,
                            interval=300,
                            timeout=30)
    elb_config3 = ElbConfig(elb_listeners_config=elb_listeners_config,
                            elb_health_check='HTTP:80/index.html',
                            elb_log_bucket='my-s3-bucket',
                            public_unit=True,
                            ssl_certificate_id=None,
                            healthy_threshold=10,
                            unhealthy_threshold=2,
                            interval=300,
                            timeout=30)

    Elb(title='MyUnit1',
        network_config=network_config,
        elb_config=elb_config1,
        template=template)

    Elb(title='MyUnit2',
        network_config=network_config,
        elb_config=elb_config2,
        template=template)
    network_config.public_hosted_zone_name = None
    Elb(title='MyUnit3',
        network_config=network_config,
        elb_config=elb_config3,
        template=template)

    print(template.to_json(indent=2, separators=(',', ': ')))
Exemple #2
0
def create_elb(instance_port='80',
               loadbalancer_port='80',
               loadbalancer_protocol='HTTP',
               instance_protocol='HTTP',
               hosted_zone_name=None,
               elb_health_check='HTTP:80/index.html',
               elb_log_bucket=None,
               public_unit=True,
               ssl_certificate_id=None,
               healthy_threshold=10,
               unhealthy_threshold=2,
               interval=300,
               timeout=30,
               sticky_app_cookie='SESSIONTOKEN'):
    """
    Helper function to create Elb Troposhpere object to interate through.
    :param instance_port - port for traffic to instances from the load balancer
    :param loadbalancer_port - port for traffic to the load balancer from public
    :param loadbalancer_protocol: protocol for traffic into ELB from World
    :param instance_protocol: protocol for traffic into ASG from ELB
    :param elb_health_check: path to test page
    :param elb_log_bucket: S3 bucket to log access log to
    :param hosted_zone_name: Route53 hosted zone ID
    :param public_unit: Boolean to determine if the elb scheme will be internet-facing or private
    :param ssl_certificate_id: SSL Certificate to attach to elb for https using AWS Certificate Manager
    :param sticky_app_cookie: Name of application cookie used for stickiness
    :return: Troposphere object for Elb
    """
    network_config, template = get_network_config()
    network_config.public_hosted_zone_name = hosted_zone_name
    elb_listeners_config = [
        ElbListenersConfig(instance_port=instance_port,
                           loadbalancer_port=loadbalancer_port,
                           loadbalancer_protocol=loadbalancer_protocol,
                           instance_protocol=instance_protocol,
                           sticky_app_cookie=sticky_app_cookie)
    ]
    elb_config = ElbConfig(elb_listeners_config=elb_listeners_config,
                           elb_health_check=elb_health_check,
                           elb_log_bucket=elb_log_bucket,
                           public_unit=public_unit,
                           ssl_certificate_id=ssl_certificate_id,
                           healthy_threshold=healthy_threshold,
                           unhealthy_threshold=unhealthy_threshold,
                           interval=interval,
                           timeout=timeout,
                           owner='*****@*****.**')

    elb = Elb(title='elb',
              template=template,
              network_config=network_config,
              elb_config=elb_config)
    return elb
def setup_resources():
    """ Setup global variables between tests"""
    global template, elb_config, network_config, common_asg_config, block_devices_config, tree_name, \
        availability_zones, cd_service_role_arn, public_cidr, public_hosted_zone_name, keypair
    tree_name = 'testtree'
    network_config, template = get_network_config()
    availability_zones = [
        'ap-southeast-2a', 'ap-southeast-2b', 'ap-southeast-2c'
    ]
    cd_service_role_arn = 'arn:aws:iam::123456789:role/CodeDeployServiceRole'
    public_cidr = {'name': 'PublicIp', 'cidr': '0.0.0.0/0'}
    public_hosted_zone_name = 'your.domain.'
    keypair = 'INSERT_YOUR_KEYPAIR_HERE'
    block_devices_config = [
        BlockDevicesConfig(device_name='/dev/xvda',
                           ebs_volume_size='15',
                           ebs_volume_type='gp2',
                           ebs_encrypted=False,
                           ebs_snapshot_id=None,
                           virtual_name=False)
    ]

    userdata = """
#cloud-config
repo_update: true
repo_upgrade: all

packages:
 - httpd

runcmd:
 - service httpd start
    """
    network_config, template = get_network_config()

    elb_listeners_config = [
        ElbListenersConfig(instance_port='80',
                           loadbalancer_port='80',
                           loadbalancer_protocol='HTTP',
                           instance_protocol='HTTP',
                           sticky_app_cookie='JSESSION')
    ]

    elb_config = ElbConfig(elb_log_bucket=None,
                           elb_listeners_config=elb_listeners_config,
                           elb_health_check='HTTP:80/index.html',
                           public_unit=True,
                           ssl_certificate_id=None,
                           healthy_threshold=10,
                           unhealthy_threshold=2,
                           interval=300,
                           timeout=30)
    common_asg_config = AsgConfig(
        minsize=1,
        maxsize=1,
        image_id='ami-dc361ebf',
        instance_type='t2.nano',
        health_check_grace_period=300,
        health_check_type='ELB',
        userdata=userdata,
        iam_instance_profile_arn=None,
        block_devices_config=block_devices_config,
        simple_scaling_policy_config=None,
        ec2_scheduled_shutdown=ec2_scheduled_shutdown)
def main():
    userdata = """
#cloud-config
repo_update: true
repo_upgrade: all

packages:
 - httpd

runcmd:
 - service httpd start
    """
    network_config, template = get_network_config()

    elb_health_check = 'TCP:80'
    healthy_threshold = 10
    unhealthy_threshold = 2
    interval = 300
    timeout = 30
    minsize = 1
    maxsize = 2
    health_check_grace_period = 300
    health_check_type = 'ELB'

    image_id = 'ami-dc361ebf'
    instance_type = 't2.nano'

    elb_listeners_config = [
        ElbListenersConfig(
            instance_port='80',
            loadbalancer_port='80',
            loadbalancer_protocol='HTTP',
            instance_protocol='HTTP',
            sticky_app_cookie='JSESSION'
        ),
        ElbListenersConfig(
            instance_port='8080',
            loadbalancer_port='8080',
            loadbalancer_protocol='HTTP',
            instance_protocol='HTTP',
            sticky_app_cookie='SESSIONTOKEN'
        )
    ]

    block_devices_config = [BlockDevicesConfig(device_name='/dev/xvda',
                                               ebs_volume_size='15',
                                               ebs_volume_type='gp2',
                                               ebs_encrypted=False,
                                               ebs_snapshot_id=None,
                                               virtual_name=False)]

    elb_config = ElbConfig(elb_listeners_config=elb_listeners_config,
                           elb_log_bucket=None,
                           elb_health_check=elb_health_check,
                           public_unit=True,
                           ssl_certificate_id=None,
                           healthy_threshold=healthy_threshold,
                           unhealthy_threshold=unhealthy_threshold,
                           interval=interval,
                           timeout=timeout,
                           owner='*****@*****.**'
                           )
    blue_asg_config = AsgConfig(health_check_grace_period=health_check_grace_period,
                                health_check_type=health_check_type,
                                minsize=minsize,
                                maxsize=maxsize,
                                image_id=image_id,
                                instance_type=instance_type,
                                userdata=userdata,
                                iam_instance_profile_arn=None,
                                block_devices_config=block_devices_config,
                                simple_scaling_policy_config=None,
                                ec2_scheduled_shutdown=None,
                                pausetime=10,
                                owner='*****@*****.**')
    green_asg_config = AsgConfig(health_check_grace_period=health_check_grace_period,
                                 health_check_type=health_check_type,
                                 minsize=minsize,
                                 maxsize=maxsize,
                                 image_id=image_id,
                                 instance_type=instance_type,
                                 userdata=userdata,
                                 iam_instance_profile_arn=None,
                                 block_devices_config=block_devices_config,
                                 simple_scaling_policy_config=None,
                                 ec2_scheduled_shutdown=None,
                                 pausetime=10,
                                 owner='*****@*****.**')
    ZdAutoscalingUnit(
        unit_title='app1',
        template=template,
        dependencies=['app2:80'],
        stack_config=network_config,
        elb_config=elb_config,
        blue_asg_config=blue_asg_config,
        green_asg_config=green_asg_config
    )
    ZdAutoscalingUnit(
        unit_title='app2',
        template=template,
        dependencies=['app1:80'],
        stack_config=network_config,
        elb_config=elb_config,
        blue_asg_config=blue_asg_config,
        green_asg_config=green_asg_config
    )

    print(template.to_json(indent=2, separators=(',', ': ')))
Exemple #5
0
def main():
    userdata1 = """#cloud-config
repo_update: true

packages:
 - httpd

write_files:
-   content: |
        <html>
        <body>
        <h1>Amazonia created this stack!</h1>
        </body>
        </html>
    path: /var/www/html/index.html
    permissions: '0644'
    owner: root:root
runcmd:
 - service httpd start
"""
    userdata2 = """#cloud-config
repo_update: true

packages:
 - httpd

write_files:
-   content: |
        <html>
        <body>
        <h1>Amazonia created this stack too!</h1>
        </body>
        </html>
    path: /var/www/html/index.html
    permissions: '0644'
    owner: root:root
runcmd:
 - service httpd start
"""

    nat_image_id = 'ami-53371f30'
    jump_image_id = 'ami-dc361ebf'
    app_image_id = 'ami-dc361ebf'
    instance_type = 't2.nano'
    block_devices_config = [BlockDevicesConfig(device_name='/dev/xvda',
                                               ebs_volume_size='15',
                                               ebs_volume_type='gp2',
                                               ebs_encrypted=False,
                                               ebs_snapshot_id=None,
                                               virtual_name=False)]
    elb_listeners_config = [ElbListenersConfig(loadbalancer_protocol='HTTP',
                                               instance_protocol='HTTP',
                                               instance_port='80',
                                               loadbalancer_port='80',
                                               sticky_app_cookie=None)]

    stack = Stack(
        code_deploy_service_role='arn:aws:iam::123456789:role/CodeDeployServiceRole',
        keypair='INSERT_YOUR_KEYPAIR_HERE',
        availability_zones=['ap-southeast-2a', 'ap-southeast-2b', 'ap-southeast-2c'],
        vpc_cidr={'name': 'VPC', 'cidr': '10.0.0.0/16'},
        jump_image_id=jump_image_id,
        jump_instance_type=instance_type,
        nat_highly_available=True,
        nat_image_id=nat_image_id,
        nat_instance_type=instance_type,
        iam_instance_profile_arn='arn:aws:iam::123456789:instance-profile/iam-instance-profile',
        owner_emails=[],
        home_cidrs=[{'name': 'GA', 'cidr': '0.0.0.0/0'}],
        public_cidr={'name': 'PublicIp', 'cidr': '0.0.0.0/0'},
        public_hosted_zone_name='gadevs.ga.',
        private_hosted_zone_name='private.lan.',
        zd_autoscaling_units=[
            {'unit_title': 'zdapp1',
             'elb_config': ElbConfig(
                 elb_listeners_config=elb_listeners_config,
                 elb_health_check='HTTP:80/index.html',
                 elb_log_bucket=None,
                 public_unit=True,
                 ssl_certificate_id=None,
                 healthy_threshold=10,
                 unhealthy_threshold=2,
                 interval=300,
                 timeout=30,
                 owner='*****@*****.**'
             ),
             'blue_asg_config': AsgConfig(
                 minsize=1,
                 maxsize=2,
                 health_check_grace_period=300,
                 health_check_type='ELB',
                 image_id=app_image_id,
                 instance_type=instance_type,
                 iam_instance_profile_arn='arn:aws:iam::123456789:instance-profile/iam-instance-profile',
                 userdata=userdata1,
                 block_devices_config=block_devices_config,
                 simple_scaling_policy_config=None,
                 ec2_scheduled_shutdown=None,
                 pausetime='10',
                 owner='*****@*****.**'
             ),
             'green_asg_config': AsgConfig(
                 minsize=1,
                 maxsize=2,
                 health_check_grace_period=300,
                 health_check_type='ELB',
                 image_id=app_image_id,
                 instance_type=instance_type,
                 iam_instance_profile_arn='arn:aws:iam::123456789:instance-profile/iam-instance-profile',
                 userdata=userdata1,
                 block_devices_config=block_devices_config,
                 simple_scaling_policy_config=None,
                 ec2_scheduled_shutdown=None,
                 pausetime='10',
                 owner='*****@*****.**'
             ),
             'dependencies': ['app2:80', 'db1:5432']}
        ],
        autoscaling_units=[{'unit_title': 'app1',
                            'asg_config': AsgConfig(
                                minsize=1,
                                maxsize=2,
                                health_check_grace_period=300,
                                health_check_type='ELB',
                                image_id=app_image_id,
                                instance_type=instance_type,
                                iam_instance_profile_arn='arn:aws:iam::123456789:iam-instance-profile',
                                userdata=userdata1,
                                block_devices_config=block_devices_config,
                                simple_scaling_policy_config=None,
                                ec2_scheduled_shutdown=None,
                                pausetime='10',
                                owner='*****@*****.**'
                            ),
                            'elb_config': ElbConfig(
                                elb_listeners_config=elb_listeners_config,
                                elb_health_check='HTTP:80/index.html',
                                elb_log_bucket=None,
                                public_unit=True,
                                ssl_certificate_id=None,
                                healthy_threshold=10,
                                unhealthy_threshold=2,
                                interval=300,
                                timeout=30,
                                owner='*****@*****.**'
                            ),
                            'dependencies': ['app2:80', 'db1:5432']},
                           {'unit_title': 'app2',
                            'asg_config': AsgConfig(
                                minsize=1,
                                maxsize=2,
                                health_check_grace_period=300,
                                health_check_type='ELB',
                                image_id=app_image_id,
                                instance_type=instance_type,
                                iam_instance_profile_arn=None,
                                userdata=userdata2,
                                block_devices_config=block_devices_config,
                                simple_scaling_policy_config=None,
                                ec2_scheduled_shutdown=None,
                                pausetime='10',
                                owner='*****@*****.**'
                            ),
                            'elb_config': ElbConfig(
                                elb_listeners_config=elb_listeners_config,
                                elb_health_check='HTTP:80/index.html',
                                elb_log_bucket=None,
                                public_unit=False,
                                ssl_certificate_id=None,
                                healthy_threshold=10,
                                unhealthy_threshold=2,
                                interval=300,
                                timeout=30,
                                owner='*****@*****.**'
                            ),
                            'dependencies': []}
                           ],
        database_units=[{'unit_title': 'db1',
                         'database_config': DatabaseConfig(
                             db_instance_type='db.t2.micro',
                             db_engine='postgres',
                             db_port='5432',
                             db_name='myDb',
                             db_hdd_size=5,
                             db_snapshot_id='amazonia-verbose-snapshot',
                             db_backup_window=None,
                             db_backup_retention=None,
                             db_maintenance_window=None,
                             db_storage_type=None,
                             owner='*****@*****.**'
                         )
                         }],
        cf_distribution_units=[],
        api_gateway_units=[],
        lambda_units=[],
        ec2_scheduled_shutdown=None,
        owner='*****@*****.**'
    )
    print(stack.template.to_json(indent=2, separators=(',', ': ')))
Exemple #6
0
def main():
    userdata = """
#cloud-config
repo_update: true
repo_upgrade: all

packages:
 - httpd

runcmd:
 - service httpd start
    """
    template = Template()

    elb_listeners_config = [
        ElbListenersConfig(instance_port='80',
                           loadbalancer_port='80',
                           loadbalancer_protocol='HTTP',
                           instance_protocol='HTTP',
                           sticky_app_cookie=[]),
        ElbListenersConfig(instance_port='8080',
                           loadbalancer_port='8080',
                           loadbalancer_protocol='HTTP',
                           instance_protocol='HTTP',
                           sticky_app_cookie='JSESSION')
    ]

    elb_config = ElbConfig(elb_health_check='TCP:80',
                           elb_log_bucket=None,
                           public_unit=True,
                           ssl_certificate_id=None,
                           healthy_threshold=10,
                           unhealthy_threshold=2,
                           interval=300,
                           timeout=30,
                           elb_listeners_config=elb_listeners_config)

    block_devices_config = [
        BlockDevicesConfig(device_name='/dev/xvda',
                           ebs_volume_size='15',
                           ebs_volume_type='gp2',
                           ebs_encrypted=False,
                           ebs_snapshot_id=None,
                           virtual_name=False)
    ]

    asg_config = AsgConfig(minsize=1,
                           maxsize=1,
                           health_check_grace_period=300,
                           health_check_type='ELB',
                           image_id='ami-dc361ebf',
                           instance_type='t2.nano',
                           userdata=userdata,
                           iam_instance_profile_arn=None,
                           block_devices_config=block_devices_config,
                           simple_scaling_policy_config=None)

    AutoscalingLeaf(leaf_title='app2',
                    template=template,
                    dependencies=['app1:80', 'app1:8080'],
                    elb_config=elb_config,
                    asg_config=asg_config,
                    availability_zones=[
                        'ap-southeast-2a', 'ap-southeast-2b', 'ap-southeast-2c'
                    ],
                    public_cidr={
                        'name': 'PublicIp',
                        'cidr': '0.0.0.0/0'
                    },
                    tree_name='tree',
                    cd_service_role_arn=None,
                    public_hosted_zone_name=None,
                    keypair='INSERT_YOUR_KEYPAIR_HERE')

    print(template.to_json(indent=2, separators=(',', ': ')))
Exemple #7
0
def create_stack(nat_highly_available=False):
    """
    Helper function to create a stack with default values
    :return new stack
    """
    global userdata, availability_zones, keypair, instance_type, code_deploy_service_role, vpc_cidr, \
        public_cidr, instance_port, loadbalancer_port, instance_protocol, loadbalancer_protocol, minsize, maxsize, \
        elb_health_check, home_cidrs, nat_image_id, jump_image_id, health_check_grace_period, health_check_type, \
        unit_image_id, db_instance_type, db_engine, db_port, owner_emails, db_backup_window, \
        db_backup_retention, db_maintenance_window, db_storage_type, block_devices_config, healthy_threshold, \
        unhealthy_threshold, interval, timeout, elb_listeners_config, sticky_app_cookies

    stack = Stack(
        code_deploy_service_role=code_deploy_service_role,
        keypair=keypair,
        availability_zones=availability_zones,
        vpc_cidr=vpc_cidr,
        public_cidr=public_cidr,
        home_cidrs=home_cidrs,
        jump_image_id=jump_image_id,
        jump_instance_type=instance_type,
        nat_image_id=nat_image_id,
        nat_instance_type=instance_type,
        public_hosted_zone_name=None,
        private_hosted_zone_name='priavte.lan.',
        iam_instance_profile_arn=None,
        owner_emails=owner_emails,
        nat_highly_available=nat_highly_available,
        ec2_scheduled_shutdown=False,
        zd_autoscaling_units=[{
            'unit_title':
            'zdapp1',
            'elb_config':
            ElbConfig(elb_listeners_config=elb_listeners_config,
                      elb_health_check=elb_health_check,
                      elb_log_bucket=None,
                      public_unit=True,
                      ssl_certificate_id=None,
                      healthy_threshold=healthy_threshold,
                      unhealthy_threshold=unhealthy_threshold,
                      interval=interval,
                      timeout=timeout),
            'blue_asg_config':
            AsgConfig(minsize=minsize,
                      maxsize=maxsize,
                      image_id=unit_image_id,
                      instance_type=instance_type,
                      health_check_grace_period=health_check_grace_period,
                      health_check_type=health_check_type,
                      userdata=userdata,
                      iam_instance_profile_arn=None,
                      block_devices_config=block_devices_config,
                      simple_scaling_policy_config=None,
                      ec2_scheduled_shutdown=None),
            'green_asg_config':
            AsgConfig(minsize=minsize,
                      maxsize=maxsize,
                      image_id=unit_image_id,
                      instance_type=instance_type,
                      health_check_grace_period=health_check_grace_period,
                      health_check_type=health_check_type,
                      userdata=userdata,
                      iam_instance_profile_arn=None,
                      block_devices_config=block_devices_config,
                      simple_scaling_policy_config=None,
                      ec2_scheduled_shutdown=None),
            'dependencies': ['app2:5432', 'db1:80'],
        }],
        autoscaling_units=[{
            'unit_title':
            'app1',
            'elb_config':
            ElbConfig(elb_listeners_config=elb_listeners_config,
                      elb_health_check=elb_health_check,
                      elb_log_bucket=None,
                      public_unit=True,
                      ssl_certificate_id=None,
                      healthy_threshold=healthy_threshold,
                      unhealthy_threshold=unhealthy_threshold,
                      interval=interval,
                      timeout=timeout),
            'asg_config':
            AsgConfig(minsize=minsize,
                      maxsize=maxsize,
                      image_id=unit_image_id,
                      instance_type=instance_type,
                      health_check_grace_period=health_check_grace_period,
                      health_check_type=health_check_type,
                      userdata=userdata,
                      iam_instance_profile_arn=None,
                      block_devices_config=block_devices_config,
                      simple_scaling_policy_config=None,
                      ec2_scheduled_shutdown=None),
            'dependencies': ['app2:80', 'db1:5432'],
        }, {
            'unit_title':
            'app2',
            'elb_config':
            ElbConfig(elb_listeners_config=elb_listeners_config,
                      elb_health_check=elb_health_check,
                      elb_log_bucket=None,
                      public_unit=True,
                      ssl_certificate_id=None,
                      healthy_threshold=healthy_threshold,
                      unhealthy_threshold=unhealthy_threshold,
                      interval=interval,
                      timeout=timeout),
            'asg_config':
            AsgConfig(minsize=minsize,
                      maxsize=maxsize,
                      image_id=unit_image_id,
                      instance_type=instance_type,
                      health_check_grace_period=health_check_grace_period,
                      health_check_type=health_check_type,
                      userdata=userdata,
                      iam_instance_profile_arn=None,
                      block_devices_config=block_devices_config,
                      simple_scaling_policy_config=None,
                      ec2_scheduled_shutdown=None),
            'dependencies': []
        }],
        database_units=[{
            'unit_title':
            'db1',
            'database_config':
            DatabaseConfig(db_instance_type=db_instance_type,
                           db_engine=db_engine,
                           db_port=db_port,
                           db_hdd_size=db_hdd_size,
                           db_snapshot_id=None,
                           db_name='MyDb',
                           db_backup_window=db_backup_window,
                           db_backup_retention=db_backup_retention,
                           db_maintenance_window=db_maintenance_window,
                           db_storage_type=db_storage_type)
        }],
        cf_distribution_units=[{
            'unit_title':
            'cfdist1',
            'cf_origins_config': [
                CFOriginsConfig(
                    domain_name='amazonia-elb-bucket.s3.amazonaws.com',
                    origin_id='S3-amazonia-elb-bucket',
                    origin_path='',
                    custom_headers={
                        'Origin': 'http://www.domain.com',
                        'Accept': 'True'
                    },
                    origin_policy={
                        'is_s3': True,
                        'origin_access_identity': 'originaccessid1'
                    }),
                CFOriginsConfig(domain_name='app1',
                                origin_id='www-elb',
                                origin_path='/path',
                                custom_headers={},
                                origin_policy={
                                    'is_s3':
                                    False,
                                    'origin_protocol_policy':
                                    'https-only',
                                    'http_port':
                                    80,
                                    'https_port':
                                    443,
                                    'origin_ssl_protocols':
                                    ['TLSv1', 'TLSv1.1', 'TLSv1.2'],
                                }),
                CFOriginsConfig(domain_name='validYamlTestAPIGW',
                                origin_id='www-elb2',
                                origin_path='/path',
                                custom_headers={},
                                origin_policy={
                                    'is_s3':
                                    False,
                                    'origin_protocol_policy':
                                    'https-only',
                                    'http_port':
                                    80,
                                    'https_port':
                                    443,
                                    'origin_ssl_protocols':
                                    ['TLSv1', 'TLSv1.1', 'TLSv1.2'],
                                })
            ],
            'cf_distribution_config':
            CFDistributionConfig(
                aliases=['www.test-stack.gadevs.ga', 'test-stack.gadevs.ga'],
                comment='SysTestCFDistribution',
                default_root_object='index.html',
                enabled=True,
                price_class='PriceClass_All',
                error_page_path='index.html',
                acm_cert_arn='arn.acm.certificate',
                minimum_protocol_version='TLSv1',
                ssl_support_method='sni-only'),
            'cf_cache_behavior_config': [
                CFCacheBehaviorConfig(
                    is_default=True,
                    path_pattern='/index.html',
                    allowed_methods=['GET', 'HEAD'],
                    cached_methods=['GET', 'HEAD'],
                    target_origin_id='S3-bucket-id',
                    forward_cookies='all',
                    forwarded_headers=['Accept', 'Set-Cookie'],
                    viewer_protocol_policy='allow-all',
                    min_ttl=0,
                    default_ttl=0,
                    max_ttl=0,
                    trusted_signers=['self'],
                    query_string='False'),
                CFCacheBehaviorConfig(
                    is_default=False,
                    path_pattern='/login.js',
                    allowed_methods=[
                        'GET', 'POST', 'HEAD', 'DELETE', 'OPTIONS', 'PATCH',
                        'PUT'
                    ],
                    cached_methods=['GET', 'HEAD'],
                    target_origin_id='www-origin',
                    forward_cookies='all',
                    forwarded_headers=['Accept', 'Set-Cookie'],
                    viewer_protocol_policy='https-only',
                    min_ttl=0,
                    default_ttl=0,
                    max_ttl=0,
                    trusted_signers=['self'],
                    query_string='True')
            ]
        }],
        api_gateway_units=[{
            'unit_title':
            'validYamlTestAPIGW',
            'method_config': [
                ApiGatewayMethodConfig(
                    method_name='login',
                    lambda_unit='validYamlTestLambda',
                    httpmethod='POST',
                    authorizationtype='NONE',
                    request_config=ApiGatewayRequestConfig(
                        templates={'application/json': ''},
                        parameters={'somemapping': 'somefield'}),
                    response_config=[
                        ApiGatewayResponseConfig(
                            templates={'application/json': ''},
                            parameters={'somemapping': 'somefield'},
                            statuscode='200',
                            models={'application/json': 'Empty'},
                            selectionpattern='')
                    ])
            ]
        }],
        lambda_units=[{
            'unit_title':
            'validYamlTestLambda',
            'dependencies': ['db1:5432'],
            'lambda_config':
            LambdaConfig(lambda_s3_bucket='bucket_name',
                         lambda_s3_key='key_name',
                         lambda_description='blah',
                         lambda_function_name='my_function',
                         lambda_handler='main',
                         lambda_memory_size=128,
                         lambda_role_arn='test_arn',
                         lambda_runtime='python2.7',
                         lambda_timeout=1,
                         lambda_schedule='cron(0/5 * * * ? *)')
        }])
    return stack
Exemple #8
0
def test_duplicate_unit_names():
    """ Test for duplicate unit names
    """

    assert_raises(
        DuplicateUnitNameError, Stack, **{
            'code_deploy_service_role':
            code_deploy_service_role,
            'keypair':
            keypair,
            'availability_zones':
            availability_zones,
            'vpc_cidr':
            vpc_cidr,
            'public_cidr':
            public_cidr,
            'home_cidrs':
            home_cidrs,
            'jump_image_id':
            jump_image_id,
            'jump_instance_type':
            instance_type,
            'nat_image_id':
            nat_image_id,
            'nat_instance_type':
            instance_type,
            'public_hosted_zone_name':
            None,
            'private_hosted_zone_name':
            'private.lan.',
            'iam_instance_profile_arn':
            None,
            'owner_emails':
            owner_emails,
            'nat_highly_available':
            False,
            'ec2_scheduled_shutdown':
            False,
            'autoscaling_units': [{
                'unit_title':
                'app1',
                'asg_config':
                AsgConfig(minsize=minsize,
                          maxsize=maxsize,
                          image_id=unit_image_id,
                          instance_type=instance_type,
                          health_check_grace_period=health_check_grace_period,
                          health_check_type=health_check_type,
                          userdata=userdata,
                          iam_instance_profile_arn=None,
                          block_devices_config=block_devices_config,
                          simple_scaling_policy_config=None,
                          ec2_scheduled_shutdown=None),
                'elb_config':
                ElbConfig(elb_listeners_config=elb_listeners_config,
                          elb_health_check=elb_health_check,
                          elb_log_bucket=None,
                          public_unit=True,
                          ssl_certificate_id=None,
                          healthy_threshold=healthy_threshold,
                          unhealthy_threshold=unhealthy_threshold,
                          interval=interval,
                          timeout=timeout),
                'dependencies': [],
            }, {
                'unit_title':
                'app1',
                'elb_config':
                ElbConfig(elb_listeners_config=elb_listeners_config,
                          elb_health_check=elb_health_check,
                          elb_log_bucket=None,
                          public_unit=True,
                          ssl_certificate_id=None,
                          healthy_threshold=healthy_threshold,
                          unhealthy_threshold=unhealthy_threshold,
                          interval=interval,
                          timeout=timeout),
                'asg_config':
                AsgConfig(minsize=minsize,
                          maxsize=maxsize,
                          image_id=unit_image_id,
                          instance_type=instance_type,
                          health_check_grace_period=health_check_grace_period,
                          health_check_type=health_check_type,
                          userdata=userdata,
                          iam_instance_profile_arn=None,
                          block_devices_config=None,
                          simple_scaling_policy_config=None,
                          ec2_scheduled_shutdown=None),
                'dependencies': [],
            }],
            'database_units': [],
            'zd_autoscaling_units': [],
            'cf_distribution_units': [],
            'api_gateway_units': [],
            'lambda_units': []
        })
Exemple #9
0
def main():
    userdata = """
#cloud-config
repo_update: true
repo_upgrade: all

packages:
 - httpd

runcmd:
 - service httpd start
    """
    network_config, template = get_network_config()

    elb_listeners_config = [
        ElbListenersConfig(instance_port='80',
                           loadbalancer_port='80',
                           loadbalancer_protocol='HTTP',
                           instance_protocol='HTTP',
                           sticky_app_cookie=None),
        ElbListenersConfig(instance_port='8080',
                           loadbalancer_port='8080',
                           loadbalancer_protocol='HTTP',
                           instance_protocol='HTTP',
                           sticky_app_cookie='JSESSION')
    ]

    elb_config = ElbConfig(elb_health_check='TCP:80',
                           elb_log_bucket=None,
                           public_unit=True,
                           ssl_certificate_id=None,
                           healthy_threshold=10,
                           unhealthy_threshold=2,
                           interval=300,
                           timeout=30,
                           elb_listeners_config=elb_listeners_config)

    block_devices_config = [
        BlockDevicesConfig(device_name='/dev/xvda',
                           ebs_volume_size='15',
                           ebs_volume_type='gp2',
                           ebs_encrypted=False,
                           ebs_snapshot_id=None,
                           virtual_name=False)
    ]

    asg_config = AsgConfig(minsize=1,
                           maxsize=1,
                           health_check_grace_period=300,
                           health_check_type='ELB',
                           image_id='ami-dc361ebf',
                           instance_type='t2.nano',
                           userdata=userdata,
                           iam_instance_profile_arn=None,
                           block_devices_config=block_devices_config,
                           simple_scaling_policy_config=None)

    AutoscalingUnit(unit_title='app1',
                    template=template,
                    dependencies=['app2:80'],
                    stack_config=network_config,
                    elb_config=elb_config,
                    asg_config=asg_config)

    AutoscalingUnit(unit_title='app2',
                    stack_config=network_config,
                    template=template,
                    elb_config=elb_config,
                    asg_config=asg_config,
                    dependencies=None)
    print(template.to_json(indent=2, separators=(',', ': ')))
def main():
    network_config, template = get_network_config()

    userdata = """
    #cloud-config
    repo_update: true
    repo_upgrade: all

    packages:
     - httpd

    runcmd:
     - service httpd start
        """
    elb_listeners_config = [
        ElbListenersConfig(
            instance_port='80',
            loadbalancer_port='80',
            loadbalancer_protocol='HTTP',
            instance_protocol='HTTP',
            sticky_app_cookie=None
        )
    ]

    elb_config = ElbConfig(
        elb_health_check='TCP:80',
        elb_log_bucket=None,
        public_unit=True,
        ssl_certificate_id=None,
        healthy_threshold=10,
        unhealthy_threshold=2,
        interval=300,
        timeout=30,
        owner='*****@*****.**',
        elb_listeners_config=elb_listeners_config
    )

    block_devices_config = [BlockDevicesConfig(device_name='/dev/xvda',
                                               ebs_volume_size='15',
                                               ebs_volume_type='gp2',
                                               ebs_encrypted=False,
                                               ebs_snapshot_id=None,
                                               virtual_name=False)
                            ]

    asg_config = AsgConfig(
        minsize=1,
        maxsize=2,
        health_check_grace_period=300,
        health_check_type='ELB',
        image_id='ami-dc361ebf',
        instance_type='t2.nano',
        userdata=userdata,
        iam_instance_profile_arn=None,
        block_devices_config=block_devices_config,
        simple_scaling_policy_config=None,
        ec2_scheduled_shutdown=None,
        pausetime='10',
        owner='*****@*****.**'
    )

    app_name = 'app1'

    AutoscalingUnit(
        unit_title=app_name,
        template=template,
        dependencies=[],
        stack_config=network_config,
        elb_config=elb_config,
        asg_config=asg_config,
        ec2_scheduled_shutdown=None
    )

    apiname = 'apigw1'
    methodname = 'login'
    lambda_title = 'MyLambda'
    httpmethod = 'POST'
    authorizationtype = 'NONE'

    request_template = {'application/json': """{ "username": $input.json('$.username')}"""}
    request_parameters = {'method.request.header.Origin': "$input.params('Origin')"}
    response_template = {'application/json': ''}
    response_parameters = {'method.response.header.Set-COokie': 'integration.response.body.TESTVALUE'}
    response_models = {'application/json': 'Empty'}
    statuscode = '200'
    selectionpattern = ''
    request_config = ApiGatewayRequestConfig(templates=request_template,
                                             parameters=request_parameters)
    response_config1 = ApiGatewayResponseConfig(templates=response_template,
                                                parameters=response_parameters,
                                                statuscode=statuscode,
                                                models=response_models,
                                                selectionpattern=selectionpattern)
    statuscode = '403'
    selectionpattern = 'Invalid.*'
    response_config2 = ApiGatewayResponseConfig(templates=response_template,
                                                parameters=response_parameters,
                                                statuscode=statuscode,
                                                models=response_models,
                                                selectionpattern=selectionpattern)

    method_config = ApiGatewayMethodConfig(method_name=methodname,
                                           lambda_unit=lambda_title,
                                           request_config=request_config,
                                           response_config=[response_config1, response_config2],
                                           httpmethod=httpmethod,
                                           authorizationtype=authorizationtype)
    lambda_config = LambdaConfig(
        lambda_s3_bucket='smallest-bucket-in-history',
        lambda_s3_key='test_lambda.zip',
        lambda_description='test function',
        lambda_function_name='test_lambda',
        lambda_handler='test_lambda.lambda_handler',
        lambda_memory_size=128,
        lambda_role_arn='arn:aws:iam::123456789:role/lambda_basic_vpc_execution_with_s3',
        lambda_runtime='python2.7',
        lambda_timeout=1,
        lambda_schedule='rate(5 minutes)'
    )

    LambdaUnit(
        unit_title=lambda_title,
        template=template,
        dependencies=[],
        stack_config=network_config,
        lambda_config=lambda_config
    )

    ApiGatewayUnit(unit_title=apiname,
                   template=template,
                   method_config=[method_config],
                   stack_config=network_config)

    origins = [
        CFOriginsConfig(
            domain_name=app_name,
            origin_id=app_name,
            origin_path='',
            custom_headers=[],
            origin_policy={
                'is_s3': False,
                'origin_protocol_policy': 'http-only',
                'http_port': 80,
                'https_port': 443,
                'origin_ssl_protocols': ['TLSv1', 'TLSv1.1', 'TLSv1.2'],
            }
        ),
        CFOriginsConfig(
            domain_name=apiname,
            origin_id=apiname,
            origin_path='/amz_deploy',
            custom_headers=[],
            origin_policy={
                'is_s3': False,
                'origin_protocol_policy': 'https-only',
                'http_port': 80,
                'https_port': 443,
                'origin_ssl_protocols': ['TLSv1', 'TLSv1.1', 'TLSv1.2'],
            }
        )
    ]

    cache_behavior = [
        CFCacheBehaviorConfig(
            is_default=True,
            path_pattern='',
            allowed_methods=['GET', 'HEAD'],
            cached_methods=['GET', 'HEAD'],
            target_origin_id='app1',
            forward_cookies='all',
            forwarded_headers=[],
            viewer_protocol_policy='allow-all',
            min_ttl=0,
            default_ttl=0,
            max_ttl=0,
            trusted_signers=[],
            query_string=True
        ),
        CFCacheBehaviorConfig(
            is_default=False,
            path_pattern='/login',
            allowed_methods=['GET', 'POST', 'HEAD', 'DELETE', 'OPTIONS', 'PATCH', 'PUT'],
            cached_methods=['GET', 'HEAD'],
            target_origin_id='apigw1',
            forward_cookies='all',
            forwarded_headers=['Accept',
                               'Accept-Charset',
                               'Accept-Datetime',
                               'Accept-Language',
                               'Authorization',
                               'Content-Type',
                               'Origin',
                               'Referer',
                               'Set-Cookie'],
            viewer_protocol_policy='https-only',
            min_ttl=0,
            default_ttl=0,
            max_ttl=0,
            trusted_signers=[],
            query_string=False
        ),
    ]

    distribution_config = CFDistributionConfig(
        aliases=[],
        comment='SysTestCFDistribution',
        default_root_object='',
        enabled=True,
        price_class='PriceClass_All',
        error_page_path='',
        acm_cert_arn=None,
        minimum_protocol_version='TLSv1',
        ssl_support_method='sni-only'
    )

    CFDistributionUnit(unit_title='cfdist',
                       template=template,
                       stack_config=network_config,
                       cf_origins_config=origins,
                       cf_cache_behavior_config=cache_behavior,
                       cf_distribution_config=distribution_config)

    print(template.to_json(indent=2, separators=(',', ': ')))