User data did not run: packages are missing and the app never started.
IntermediateTroubleshootingEC2, Auto Scaling and Load Balancing
Answer
Likely causes → The script has no shebang, or it was saved with CRLF line endings. It may have failed part-way. Or it already ran once: by default, user data runs only on the first boot, so editing it on a stopped instance does nothing.
Diagnose →
aws ec2 describe-instance-attribute --instance-id i-0abc --attribute userData \
--query UserData.Value --output text | base64 -d | head
sudo cat /var/log/cloud-init-output.log
sudo grep -i error /var/log/cloud-init.log
cloud-init status --long
Fix →
- Start the script with
#!/bin/bashand addset -euxo pipefailso failures show up - Convert the file to LF line endings
- To re-run it for testing, run
sudo cloud-init clean && sudo reboot
Prevent → Keep user data small: bootstrap a config tool or pull a versioned script. Better still, bake an AMI with Packer.