Interview Prep/AWS/EC2, Auto Scaling and Load Balancing

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 →

  1. Start the script with #!/bin/bash and add set -euxo pipefail so failures show up
  2. Convert the file to LF line endings
  3. 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.

aws All AWS questions Roadmap: AWS core services

More on EC2, Auto Scaling and Load Balancing