[aws-ec2] cfn-init installation hooks
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
When I add an `init` section to my EC2 instance that I am booting using an Amazon Linux 2 AMI, the stack fails to deploy because CFN never receives the signal callback from the node.
It appears to me that the root cause is that adding the `init` section in CDK causes some UserData to be added to make a call to `/opt/aws/bin/cfn-init` (which is great!), but on this AMI, that script is not installed. So we probably need to do a yum install before the call to cfn-init... I can't immediately see how to do that, as calls to "addUserData" after the instance object is instantiated result in adding new things to userdata *after* the cfn-init command.
### Reproduction Steps
```
const instance = new ec2.Instance(this, 'MyInstance', {
instanceType: ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.MICRO),
machineImage: ec2.MachineImage.lookup({
name: 'amzn2-ami-ecs-hvm-2.0.20200813-x86_64-ebs',
}),
vpc: vpc,
securityGroup: securityGroup,
init: ec2.CloudFormationInit.fromElements(
ec2.InitCommand.shellCommand('sudo yum install tmux'),
),
initOptions: {
timeout: cdk.Duration.minutes(15)
}
})
```
### What did you expect to happen?
Node to boot up and have executed the init commands.
### What actually happened?
Stack deploy failed after the cfn init timeout expired.
### Environment
- **CLI Version :** 1.59.0
- **Framework Version:** 1.59.0
- **Node.js Version:** 14.7.0
- **OS :** OSX for cdk env, AL2 for EC2 instance
- **Language (Version):** TypeScript
### Other
---
This is :bug: Bug Report
Contributor guide
Research direction
Start by tracing EC2 Instance initialization and the UserData added through addUserData, focusing on the ordering around the /opt/aws/bin/cfn-init call. Reproduce the Amazon Linux 2 deployment with the provided CloudFormationInit example and verify that initialization completes and the signal callback is received before the timeout.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, linux, typescript
- Domain
- cloud, infrastructure
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100