'user-data shell is not executed when an EC2 instance launched by ASG/Launch Configuration with custom AMI
I have a set of Auto scaling group and launch configuration to manage certain EC2 instances. After changing the AMI to a custom AMI, the user data script that I set in the launch configuration is not executed at the instance startup time. (This Custom AMI is built with Packer)
The user data I've set in the launch configuration is as below:
#!/bin/bash
yum install -y git
If I connect the instance via ssh, then I can see an unknown cloud-init directives in the /var/lib/cloud/instance/user-data.txt
path as below:
#cloud-config
runcmd:
- [sh, -c, "mkdir /home/company/.ssh"]
- [sh, -c, "echo 'ssh-rsa ... > /home/company/.ssh/authorized_keys"]
- [sh, -c, "chmod 0600 /home/company/.ssh/authorized_keys"]
- [sh, -c, "chown -R company:company /home/company/.ssh"]
What I have tried to are :
- Added
#cloud-boothook
at the top of user data -> Doesn't work - Asked a person who created the custom AMI and he/she said they cannot solve this issue because if they test by themselves with the user data, it works fine in AWS Console EC2 launch menu.
Is there any approach to handle this issue?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|