When you use CFN to provision an ASG with LifeCycle events which trigger on instance launches, the issue is that CFN first creates an ASG. ASG immediately starts spinning up instances based on ASG settings. LifeCycle hooks get created usually with some delay.
This causes some instances to get launched without being “monitored” by the “launch” lifecylce hooks.
- ASG set to 0/0/0 in CFN
- Custom resource which has “DependsOn” lifecycle resource for instance launches
- Lambda function which can perform “updateAutoScalingGroup”(called by custom resource)
- IAM execution role for lambda (as/updateAutoScalingGroup)
Region which supports Lambda
CFN command to create stack
You can just change “create-stack” -> “update-stack” if you want to update the stack instead of create a new one.
You need to upload the lambda function zip to an S3 bucket, and then provide bucket name / object name in parameters