Пример #1
0
app_launch_config = LaunchConfiguration(config['name'] + 'LaunchConfig')
app_launch_config.AssociatePublicIpAddress = True
app_launch_config.EbsOptimized = config['app_launch_config']['ebs_optimized']
app_launch_config.ImageId = config['app_launch_config']['image_id']
app_launch_config.KeyName = config['app_launch_config']['key_name']
app_launch_config.InstanceType = config['app_launch_config']['instance_type']
app_launch_config.BlockDeviceMappings = [block_device_mapping]
app_launch_config.SecurityGroups = [Ref(config['name'] + 'homeSsh'), Ref(consul_sg), Ref(elb_sg)]
t.add_resource(app_launch_config)

# auto scale group for application
app_asg = AutoScalingGroup(config['name'] + 'Asg')
app_asg.AvailabilityZones = config['app_asg']['availability_zones']
app_asg.LaunchConfigurationName = Ref(app_launch_config)
app_asg.LoadBalancerNames = [Ref(load_balancer)]
app_asg.MaxSize = config['app_asg']['max_size']
app_asg.MinSize = config['app_asg']['min_size']
app_asg.VPCZoneIdentifier = [Ref(subnet.title) for subnet in app_subnets]
name_tag = {'Key': 'Name', 'Value': config['app_asg']['instance_name'], 'PropagateAtLaunch': True}
app_asg.Tags = [name_tag]
t.add_resource(app_asg)

# print the template to screen
print(t.to_json())

# write to file
cloudformation_file = 'final-project.json'
f = open(cloudformation_file, 'w')
f.write(t.to_json())
f.close()