def main(): network_config, template = get_network_config() 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=None, db_backup_window='17:00-17:30', db_backup_retention='4', db_maintenance_window='Mon:01:00-Mon:01:30', db_storage_type='gp2' ) # Test RDS DatabaseUnit(unit_title='MyDb', stack_config=network_config, template=template, database_config=database_config ) # Test RDS with SnapshotID database_config.db_snapshot_id = 'amazonia-verbose-snapshot' DatabaseUnit(unit_title='MyDb2', stack_config=network_config, template=template, database_config=database_config ) print(template.to_json(indent=2, separators=(',', ': ')))
def main(): network_config, template = get_network_config() 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)' ) # Test Lambda LambdaUnit(unit_title='MyLambda', stack_config=network_config, template=template, dependencies=[], lambda_config=lambda_config ) print(template.to_json(indent=2, separators=(',', ': ')))
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=(',', ': ')))
def main(): network_config, template = get_network_config() 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=None, db_backup_window='17:00-17:30', db_backup_retention='4', db_maintenance_window='Mon:01:00-Mon:01:30', db_storage_type='gp2', owner='*****@*****.**') # Test RDS DatabaseUnit(unit_title='MyDb', stack_config=network_config, template=template, database_config=database_config) # Test RDS with SnapshotID database_config.db_snapshot_id = 'amazonia-verbose-snapshot' DatabaseUnit(unit_title='MyDb2', stack_config=network_config, template=template, database_config=database_config) print(template.to_json(indent=2, separators=(',', ': ')))
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 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 test_cf_distribution_unit(): """ Test CF distribution unit structure """ network_config, template = get_network_config() cf_dist_config = create_cf_distribution_config() origins = [create_s3_origin(), create_s3_origin()] default_behaviour = create_cache_behavior() default_behaviour.is_default = True cache_behaviors = [default_behaviour, create_cache_behavior()] unit_title = 'testcf' cf_dist_unit = CFDistributionUnit(unit_title=unit_title, cf_distribution_config=cf_dist_config, stack_config=network_config, cf_origins_config=origins, cf_cache_behavior_config=cache_behaviors, template=template) assert_equals(cf_dist_unit.title, unit_title)
def test_cf_distribution_tree(): """ Test CF distribution leaf structure """ network_config, template = get_network_config() cf_dist_config = create_cf_distribution_config() origins = [create_s3_origin(), create_s3_origin()] default_behaviour = create_cache_behavior() default_behaviour.is_default = True cache_behaviors = [default_behaviour, create_cache_behavior()] leaf_title = 'testcf' tree_name = 'testtree' cf_dist_unit = CFDistributionLeaf(leaf_title=leaf_title, cf_distribution_config=cf_dist_config, tree_name=tree_name, cf_origins_config=origins, cf_cache_behavior_config=cache_behaviors, template=template) assert_equals(cf_dist_unit.title, leaf_title)
def setup_resources(): """ Setup global variables between tests""" global template, network_config, lambda_config, availability_zones, public_cidr network_config, template = get_network_config() availability_zones = [ 'ap-southeast-2a', 'ap-southeast-2b', 'ap-southeast-2c' ] public_cidr = {'name': 'PublicIp', 'cidr': '0.0.0.0/0'} 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 * * * ? *)')
def setup_resources(): """ Setup global variables between tests""" global template, network_config, database_config, tree_name, availability_zones network_config, template = get_network_config() availability_zones = ['ap-southeast-2a', 'ap-southeast-2b', 'ap-southeast-2c'] tree_name = 'testtree' database_config = DatabaseConfig( db_instance_type='db.t2.micro', db_engine='postgres', db_port='5432', db_name='MyDb', db_snapshot_id=None, db_hdd_size=5, db_backup_window='17:00-17:30', db_backup_retention='4', db_maintenance_window='Mon:01:00-Mon:01:30', db_storage_type='gp2' )
def setup_resources(): """ Setup global variables between tests""" global template, network_config, lambda_config, availability_zones, public_cidr network_config, template = get_network_config() availability_zones = ['ap-southeast-2a', 'ap-southeast-2b', 'ap-southeast-2c'] public_cidr = {'name': 'PublicIp', 'cidr': '0.0.0.0/0'} 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 * * * ? *)' )
def setup_resources(): """ Setup global variables between tests""" global template, network_config, database_config, tree_name, availability_zones network_config, template = get_network_config() availability_zones = [ 'ap-southeast-2a', 'ap-southeast-2b', 'ap-southeast-2c' ] tree_name = 'testtree' database_config = DatabaseConfig( db_instance_type='db.t2.micro', db_engine='postgres', db_port='5432', db_name='MyDb', db_snapshot_id=None, db_hdd_size=5, db_backup_window='17:00-17:30', db_backup_retention='4', db_maintenance_window='Mon:01:00-Mon:01:30', db_storage_type='gp2')
def setup_resources(): """ Initialise resources before each test """ global template, network_config, apiname, methodname, httpmethod, authorizationtype, request_template, \ lambda_title, request_parameters, response_template, response_parameters, response_models, selection_pattern, \ statuscode, tree_name tree_name = 'testtree' network_config, template = get_network_config() apiname = 'test0' methodname = 'login0' httpmethod = 'POST' authorizationtype = 'NONE' lambda_title = 'lambdatest1' 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' selection_pattern = ''
def main(): network_config, template = get_network_config() 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)') # Test Lambda LambdaUnit(unit_title='MyLambda', stack_config=network_config, template=template, dependencies=[], lambda_config=lambda_config) print(template.to_json(indent=2, separators=(',', ': ')))
def main(): userdata = """ #cloud-config repo_update: true repo_upgrade: all packages: - httpd runcmd: - service httpd start """ network_config, template = get_network_config() load_balancer = template.add_resource(elb.LoadBalancer('MyELB', CrossZone=True, HealthCheck=elb.HealthCheck( Target='HTTP:8080/error/noindex.html', HealthyThreshold='2', UnhealthyThreshold='5', Interval='15', Timeout='5'), Listeners=[elb.Listener(LoadBalancerPort='80', Protocol='HTTP', InstancePort='80', InstanceProtocol='HTTP')], Scheme='internet-facing', Subnets=network_config.public_subnets)) 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)] simple_scaling_policy_config = [ SimpleScalingPolicyConfig(name='heavy - load', description='When under heavy CPU load for five minutes, add two instances, ' 'wait 45 seconds', metric_name='CPUUtilization', comparison_operator='GreaterThanThreshold', threshold='45', evaluation_periods=1, period=300, scaling_adjustment=1, cooldown=45), SimpleScalingPolicyConfig(name='light - load', description='When under light CPU load for 6 consecutive periods of five minutes,' ' remove one instance, wait 120 seconds', metric_name='CPUUtilization', comparison_operator='LessThanOrEqualToThreshold', threshold='15', evaluation_periods=6, period=300, scaling_adjustment=-1, cooldown=120), SimpleScalingPolicyConfig(name='medium - load', description='When under medium CPU load for five minutes, add one instance, ' 'wait 45 seconds', metric_name='CPUUtilization', comparison_operator='GreaterThanOrEqualToThreshold', threshold='25', evaluation_periods=1, period=300, scaling_adjustment=1, cooldown=120) ] asg_config = AsgConfig( image_id='ami-dc361ebf', instance_type='t2.nano', minsize=1, maxsize=1, userdata=userdata, health_check_grace_period=300, health_check_type='ELB', iam_instance_profile_arn='arn:aws:iam::12345678987654321:role/InstanceProfileRole', block_devices_config=block_devices_config, simple_scaling_policy_config=simple_scaling_policy_config ) Asg(title='simple', network_config=network_config, load_balancers=[load_balancer], template=template, asg_config=asg_config ) print(template.to_json(indent=2, separators=(',', ': ')))
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=(',', ': ')))
def setup_resources(): """ Setup global variables between tests""" global template, network_config, elb_config, asg_config, keypair, tree_name, availability_zones, \ cd_service_role_arn, public_cidr, public_hosted_zone_name, ec2_scheduled_shutdown 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='', virtual_name=False)] asg_config = AsgConfig( userdata=""" #cloud-config repo_update: true repo_upgrade: all packages: - httpd runcmd: - service httpd start """, health_check_grace_period=300, health_check_type='ELB', iam_instance_profile_arn='arn:aws:iam::123456789:instance-profile/iam-instance-profile', image_id='ami-dc361ebf', instance_type='t2.nano', maxsize=1, minsize=1, block_devices_config=block_devices_config, simple_scaling_policy_config=None, ec2_scheduled_shutdown=ec2_scheduled_shutdown, pausetime='10', owner='*****@*****.**' ) elb_listeners_config = [ ElbListenersConfig( instance_port='80', loadbalancer_port='80', loadbalancer_protocol='HTTP', instance_protocol='HTTP', sticky_app_cookie='JSESSION' )] 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='*****@*****.**' )
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() 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) 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=(',', ': ')))
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() load_balancer = template.add_resource(elb.LoadBalancer('MyELB', CrossZone=True, HealthCheck=elb.HealthCheck( Target='HTTP:8080/error/noindex.html', HealthyThreshold='2', UnhealthyThreshold='5', Interval='15', Timeout='5'), Listeners=[elb.Listener(LoadBalancerPort='80', Protocol='HTTP', InstancePort='80', InstanceProtocol='HTTP')], Scheme='internet-facing', Subnets=network_config.public_subnets)) 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), BlockDevicesConfig(device_name='/dev/xvda2', ebs_volume_size='15', ebs_volume_type='gp2', ebs_encrypted=False, ebs_snapshot_id='ami-ce0531ad', virtual_name=False), BlockDevicesConfig(device_name='/dev/sda1', ebs_volume_size=None, ebs_volume_type=None, ebs_encrypted=False, ebs_snapshot_id=None, virtual_name=True), BlockDevicesConfig(device_name='/dev/sda2', ebs_volume_size='15', ebs_volume_type='gp2', ebs_encrypted=True, ebs_snapshot_id=None, virtual_name=False) ] asg_config = AsgConfig( image_id='ami-dc361ebf', instance_type='t2.nano', minsize=1, maxsize=1, userdata='', health_check_grace_period=300, health_check_type='ELB', iam_instance_profile_arn='arn:aws:iam::12345678987654321:role/InstanceProfileRole', block_devices_config=block_devices_config, simple_scaling_policy_config=None ) Asg(title='simple', network_config=network_config, load_balancers=[load_balancer], template=template, asg_config=asg_config ) print(template.to_json(indent=2, separators=(',', ': ')))
def setup_resources(): """ Initialise resources before each test """ global template, asg_config, elb_config, network_config, load_balancer network_config, template = get_network_config() block_devices_config = [BlockDevicesConfig( device_name='/dev/xvda', ebs_volume_size='15', ebs_volume_type='gp2', ebs_encrypted=False, ebs_snapshot_id='', virtual_name=False)] simple_scaling_policy_config = [ SimpleScalingPolicyConfig(name='heavy - load', description='When under heavy CPU load for five minutes, add two instances, ' 'wait 45 seconds', metric_name='CPUUtilization', comparison_operator='GreaterThanThreshold', threshold='45', evaluation_periods=1, period=300, scaling_adjustment=1, cooldown=45), SimpleScalingPolicyConfig(name='light - load', description='When under light CPU load for 6 consecutive periods of five minutes,' ' remove one instance, wait 120 seconds', metric_name='CPUUtilization', comparison_operator='LessThanOrEqualToThreshold', threshold='15', evaluation_periods=6, period=300, scaling_adjustment=-1, cooldown=120), SimpleScalingPolicyConfig(name='medium - load', description='When under medium CPU load for five minutes, add one instance, ' 'wait 45 seconds', metric_name='CPUUtilization', comparison_operator='GreaterThanOrEqualToThreshold', threshold='25', evaluation_periods=1, period=300, scaling_adjustment=1, cooldown=120) ] asg_config = AsgConfig( userdata=""" #cloud-config repo_update: true repo_upgrade: all packages: - httpd runcmd: - service httpd start """, health_check_grace_period=300, health_check_type='ELB', iam_instance_profile_arn= 'arn:aws:iam::123456789:instance-profile/iam-instance-profile', image_id='ami-dc361ebf', instance_type='t2.micro', maxsize=1, minsize=1, block_devices_config=block_devices_config, simple_scaling_policy_config=simple_scaling_policy_config, ec2_scheduled_shutdown=None ) load_balancer = elb.LoadBalancer('testElb', CrossZone=True, HealthCheck=elb.HealthCheck(Target='HTTP:8080/error/noindex.html', HealthyThreshold='2', UnhealthyThreshold='5', Interval='15', Timeout='5'), Listeners=[elb.Listener(LoadBalancerPort='80', Protocol='HTTP', InstancePort='80', InstanceProtocol='HTTP')], Scheme='internet-facing', Subnets=network_config.public_subnets)
def main(): network_config, template = get_network_config() load_balancer = template.add_resource( elb.LoadBalancer('MyELB', CrossZone=True, HealthCheck=elb.HealthCheck( Target='HTTP:8080/error/noindex.html', HealthyThreshold='2', UnhealthyThreshold='5', Interval='15', Timeout='5'), Listeners=[ elb.Listener(LoadBalancerPort='80', Protocol='HTTP', InstancePort='80', InstanceProtocol='HTTP') ], Scheme='internet-facing', Subnets=network_config.public_subnets)) 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), BlockDevicesConfig(device_name='/dev/xvda2', ebs_volume_size='15', ebs_volume_type='gp2', ebs_encrypted=False, ebs_snapshot_id='ami-ce0531ad', virtual_name=False), BlockDevicesConfig(device_name='/dev/sda1', ebs_volume_size=None, ebs_volume_type=None, ebs_encrypted=False, ebs_snapshot_id=None, virtual_name=True), BlockDevicesConfig(device_name='/dev/sda2', ebs_volume_size='15', ebs_volume_type='gp2', ebs_encrypted=True, ebs_snapshot_id=None, virtual_name=False) ] asg_config = AsgConfig( image_id='ami-dc361ebf', instance_type='t2.nano', minsize=1, maxsize=2, userdata='', health_check_grace_period=300, health_check_type='ELB', iam_instance_profile_arn= 'arn:aws:iam::12345678987654321:role/InstanceProfileRole', block_devices_config=block_devices_config, simple_scaling_policy_config=None, ec2_scheduled_shutdown=None, pausetime='10', owner='*****@*****.**') Asg(title='simple', network_config=network_config, load_balancers=[load_balancer], template=template, asg_config=asg_config) print(template.to_json(indent=2, separators=(',', ': ')))
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(): network_config, template = get_network_config() 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) print(template.to_json(indent=2, separators=(',', ': ')))
def setup_resources(): """ Initialise resources before each test """ global template, asg_config, elb_config, network_config, load_balancer network_config, template = get_network_config() block_devices_config = [ BlockDevicesConfig(device_name='/dev/xvda', ebs_volume_size='15', ebs_volume_type='gp2', ebs_encrypted=False, ebs_snapshot_id='', virtual_name=False) ] simple_scaling_policy_config = [ SimpleScalingPolicyConfig( name='heavy - load', description= 'When under heavy CPU load for five minutes, add two instances, ' 'wait 45 seconds', metric_name='CPUUtilization', comparison_operator='GreaterThanThreshold', threshold='45', evaluation_periods=1, period=300, scaling_adjustment=1, cooldown=45), SimpleScalingPolicyConfig( name='light - load', description= 'When under light CPU load for 6 consecutive periods of five minutes,' ' remove one instance, wait 120 seconds', metric_name='CPUUtilization', comparison_operator='LessThanOrEqualToThreshold', threshold='15', evaluation_periods=6, period=300, scaling_adjustment=-1, cooldown=120), SimpleScalingPolicyConfig( name='medium - load', description= 'When under medium CPU load for five minutes, add one instance, ' 'wait 45 seconds', metric_name='CPUUtilization', comparison_operator='GreaterThanOrEqualToThreshold', threshold='25', evaluation_periods=1, period=300, scaling_adjustment=1, cooldown=120) ] asg_config = AsgConfig( userdata=""" #cloud-config repo_update: true repo_upgrade: all packages: - httpd runcmd: - service httpd start """, health_check_grace_period=300, health_check_type='ELB', iam_instance_profile_arn= 'arn:aws:iam::123456789:instance-profile/iam-instance-profile', image_id='ami-dc361ebf', instance_type='t2.micro', maxsize=1, minsize=1, block_devices_config=block_devices_config, simple_scaling_policy_config=simple_scaling_policy_config, ec2_scheduled_shutdown=None) load_balancer = elb.LoadBalancer('testElb', CrossZone=True, HealthCheck=elb.HealthCheck( Target='HTTP:8080/error/noindex.html', HealthyThreshold='2', UnhealthyThreshold='5', Interval='15', Timeout='5'), Listeners=[ elb.Listener(LoadBalancerPort='80', Protocol='HTTP', InstancePort='80', InstanceProtocol='HTTP') ], Scheme='internet-facing', Subnets=network_config.public_subnets)
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, owner='*****@*****.**' ) 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, owner='*****@*****.**' ) 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, owner='*****@*****.**' ) 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=(',', ': ')))