We configure AWS EC2 instances (Ubuntu 20.04) with cloud-init using user-data scripts. We're noticing the user-data scripts don't execute if they are run on instance which is launched from a custom AMI created from another launched instance.
We create an intermediate AMI which has common tools & frameworks and reuse it for specific needs -
- First, we launch an instance from a published AMI. The user-data scripts get executed perfectly fine as first boot on this instance.
- We create an intermediate AMI from the instance launched in first step.
- Then launch another instance from the intermediate AMI.
We provide user-data script in the instance launched from intermediate AMI as well but somehow the script doesn't execute. I observed that the cloud-init
's metadata crawler service (cloud-init.service
) doesn't run in the step 3 and hence the user scripts are not executed.
We've already tried to clean the cloud-init cache before creating the intermediate AMI so that the cloud-init can run as first boot on the new instance [Reference] -
sudo cloud-init clean --logs --seed
And I've also tried to clean the /etc/machine-id
as shared here but nothing works.
Is there anything I'm missing to clean for cloud-init so that it can run as first boot for new instances?