Ejemplo n.º 1
0
def create_launch_template_resource(template,
                                    api_launch_template_name_variable,
                                    api_instance_class_parameter,
                                    ec2_instance_profile_resource,
                                    api_security_group_resource,
                                    ecs_cluster_resource):
    return template.add_resource(
        ec2.LaunchTemplate(
            'LaunchTemplate',
            LaunchTemplateName=api_launch_template_name_variable,
            LaunchTemplateData=ec2.LaunchTemplateData(
                ImageId='ami-0ae254c8a2d3346a7',
                InstanceType=Ref(api_instance_class_parameter),
                IamInstanceProfile=ec2.IamInstanceProfile(
                    Arn=GetAtt(ec2_instance_profile_resource, 'Arn')),
                InstanceInitiatedShutdownBehavior='terminate',
                Monitoring=ec2.Monitoring(Enabled=True),
                SecurityGroups=[Ref(api_security_group_resource)],
                BlockDeviceMappings=[
                    ec2.BlockDeviceMapping(DeviceName='/dev/xvdcz',
                                           Ebs=ec2.EBSBlockDevice(
                                               DeleteOnTermination=True,
                                               VolumeSize=22,
                                               VolumeType='gp2'))
                ],
                UserData=Base64(
                    Join('', [
                        '#!/bin/bash\n', 'echo ECS_CLUSTER=',
                        Ref(ecs_cluster_resource),
                        ' >> /etc/ecs/ecs.config;echo ECS_BACKEND_HOST= >> /etc/ecs/ecs.config;'
                    ])))))
Ejemplo n.º 2
0
        'ApiCluster'
    )
)

launch_template = template.add_resource(
    ec2.LaunchTemplate(
        'LaunchTemplate',
        LaunchTemplateName=Ref(api_launch_template_name),
        LaunchTemplateData=ec2.LaunchTemplateData(
            ImageId='ami-066826c6a40879d75',
            InstanceType=Ref(api_instance_class),
            IamInstanceProfile=ec2.IamInstanceProfile(
                Arn=GetAtt(ec2_instance_profile, 'Arn')
            ),
            InstanceInitiatedShutdownBehavior='terminate',
            Monitoring=ec2.Monitoring(Enabled=True),
            SecurityGroups=[Ref(api_security_group)],
            BlockDeviceMappings=[
                ec2.BlockDeviceMapping(
                    DeviceName='/dev/xvdcz',
                    Ebs=ec2.EBSBlockDevice(
                        DeleteOnTermination=True,
                        VolumeSize=22,
                        VolumeType='gp2'
                    )
                )
            ],
            UserData=Base64(
                Join('', [
                    '#!/bin/bash\n',
                    'echo ECS_CLUSTER=',