sigdba / sig-shared-sceptre

Shared templates for Sceptre/CloudFormation
2 stars 0 forks source link

EcsCluster: launch configurations have been deprecated by AWS #145

Open gillfimj opened 5 days ago

gillfimj commented 5 days ago

AWS is deprecating launch configurations in favor of launch templates:

New instance types Starting December 31, 2022, new Amazon EC2 instance types can't be used to create launch configurations.

New accounts Starting June 1, 2023, new accounts can't create launch configurations through the console.

New account creation Starting October 1, 2024, new accounts can't create launch configurations using the console, API, CLI, or CloudFormation.

The current version of EcsCluster uses Launch Configurations to create the auto-scaling group. I believe this will need to be updated to address the deprecation before anyone attempts to run a cluster update.

Affected code segments:

from troposphere.autoscaling import (
    AutoScalingGroup,
    LaunchConfiguration,

...

def auto_scaling_group(
    name, subnets, launch_conf, max_size, max_lifetime_days, desired_size, tags
):
    return add_resource(
        AutoScalingGroup(
            "Asg" + name,
            VPCZoneIdentifier=subnets,
            LaunchConfigurationName=Ref(launch_conf),

...

def launch_config(
    name, sgs, inst_type, inst_prof, keyName, extra_node_user_data, allow_imds1
):
    metadata_options = MetadataOptions(HttpTokens="optional") if allow_imds1 else None
    return add_resource(
        LaunchConfiguration(
            "LaunchConf" + name,
            ImageId=Ref("AmiId"),
            SecurityGroups=sgs,
            InstanceType=inst_type,
            IamInstanceProfile=Ref(inst_prof),
            KeyName=keyName,
            UserData=Base64(
                Sub(read_resource("UserData.txt"), ExtraUserData=extra_node_user_data)
            ),
            **opts_with(MetadataOptions=metadata_options)
        )
    )

...

def scaling_group_with_resources(
    security_groups, node_profile, subnets, tags, sg_model
):
    lc = launch_config(
        sg_model.name,
        security_groups,
        sg_model.node_type,
        node_profile,
        sg_model.key_name,
        sg_model.extra_node_user_data,
        sg_model.allow_imds1,
    )