ec2: cfn-init support in ASGs
See original GitHub issueI want to use the logical ID of the resource created in the construct library.
For example, cfn-signal
require AutoScalingGroup’s logical id.
I wrote this code.
const asg = cluster.addDefaultAutoScalingGroupCapacity({
instanceType: new ec2.InstanceType("t2.xlarge"),
instanceCount: 1,
});
const appLaunchTemplate = new ec2.cloudformation.LaunchTemplateResource(this, 'AppLaunchTemplate', {
launchTemplateName: "launchtemplatetest",
launchTemplateData: {
userData: new cdk.FnBase64([
`#!/bin/sh`,
`set -e`,
`echo ECS_CLUSTER=${cluster.clusterName} >> /etc/ecs/ecs.config`,
`/opt/aws/bin/cfn-signal -e $? --stack ${new cdk.AwsStackName()} --resource ${asg.autoScalingGroupName} --region ${new cdk.AwsRegion}`,
].join('\n')
),
}
})
appLaunchTemplate.addDependency(instanceProfile)
const asgResource = asg.findChild('ASG') as autoscaling.cloudformation.AutoScalingGroupResource
asgResource.addPropertyDeletionOverride('LaunchConfigurationName')
asgResource.addPropertyOverride('LaunchTemplate', {
LaunchTemplateId: appLaunchTemplate.ref,
Version: '1'
})
However Circular dependency caused.
SampleStack failed: ValidationError: Circular dependency between resources: [AppLaunchTemplate, ClusterDefaultAutoScalingGroupLifecycleHookDrainHook4A9A4325, ClusterDefaultAutoScalingGroupASG0F98E147]
Circular dependency between resources: [AppLaunchTemplate, ClusterDefaultAutoScalingGroupLifecycleHookDrainHook4A9A4325, ClusterDefaultAutoScalingGroupASG0F98E147]
This will be solved by specifying a name or not have a hash in construct library.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:12 (7 by maintainers)
Top Results From Across the Web
cfn-signal - AWS CloudFormation
Description. The cfn-signal helper script signals CloudFormation to indicate whether Amazon EC2 instances have been successfully created or updated.
Read more >How to use cfn-init to set up EC2 instances with CloudFormation
You can run the cfn-init command if you SSH into the instance too, which makes a quick deploy-try out process. Just right click...
Read more >6 unknown CloudFormation features you should know about
cfn -init is executed in the user data script and fetches configuration information from your CloudFormation stack. The configuration is attached ...
Read more >Issue with cfn-signal and auto scaling groups using launch ...
The instance user data invokes cfn-signal after cfn-init has ... Instance in ASG gets brought down (minimum instance in service is 0 in...
Read more >CloudFormation cfn-init breaking in AWS::EC2 - Stack Overflow
This could be because --resource LaunchTemplate is incorrect. It should the ASG or instance resource that uses the launchtemplate, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For future reference, this is how you can get the logical ID for the autoscaling group:
This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.