aws / aws/aws-cdk

aws-autoscaling: Support Default version of a LaunchTemplate

Open
#23,127 7 comments 18 reactions 0 assignees View on GitHub
@aws-cdk/aws-autoscaling effort/small feature-request needs-cfn p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the feature

The CDK AutoScalingGroup L2 Construct does not expose the `Default` or `Latest` version from a LaunchTemplate, rather it will use the version of the LaunchTemplate L2 construct.

One could try to use the escape hatch like so:

```typescript
const cfnASG = asg.node.defaultChild as autoscaling.CfnAutoScalingGroup;
const ltLogicalId = this.getLogicalId(launchTemplate.node.defaultChild as ec2.CfnLaunchTemplate);
cfnASG.launchTemplate = {
launchTemplateName: ltName,
version: core.Fn.getAtt(ltLogicalId, "DefaultVersionNumber").toString(),
};
```

But that would just use the `Default` at the time of deployment.

### Use Case

I have several LaunchTemplates (LTs) and I build ASGs on top of these LTs. I also update the AMIs through ImageBuilder. When a new AMI is built in ImageBuilder, it updates the LT with a new `Default` version, and the ASG uses always the `Default`, so no changes to the ASG is needed after creation.

### Proposed Solution

As it is now, this cannot be achieved in Cfn or CDK AFAICS. Any deployment could overwrite the ASG. The root cause is that `Default` [is not an allowed value](1) in CloudFormation.

As a workaround, I imagine a Cfn Custom Resource could be built for AutoScalingGroup that does this, but I would like to avoid writing one if there's a solution/workaround for this.

[1]: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-autoscaling-autoscalinggroup-launchtemplatespecification.html

### Other Information

_No response_

### Acknowledgements

- [X] I may be able to implement this feature request
- [ ] This feature might incur a breaking change

### CDK version used

2.45.0

### Environment details (OS name and version, etc.)

Ubuntu 20.04

Contributor guide

Open the contributing guide

Research direction

Start at the CDK AutoScalingGroup L2 construct and its LaunchTemplate handling, then compare the CloudFormation LaunchTemplateSpecification constraints linked in the issue. Determine how Default or Latest could be represented without later deployments overwriting the Auto Scaling group configuration; done means the feature is exposed while preserving the described ImageBuilder workflow.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cloud, infrastructure
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.