Search code examples
amazon-web-servicesamazon-s3amazon-ec2amazon-vpcaws-vpc

User Data is not running on EC2 instance in Private VPC subnet


This is the user data used:

#!/bin/bash
yum install httpd -y
yum update -y
aws s3 cp s3://YOURBUCKETNAMEHERE/index.html /var/www/html/
service httpd start
chkconfig httpd on

NAT gateway is configured for the private EC2 instance and also s3fullaccess permissions are given.

Please help me troubleshoot!


Solution

  • You can add some code to the start of your user-data script to redirect the output to logs.

    exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1

    Then you can use those logs to troubleshoot from the AWS Console. Select the instance, then Actions menu -> Instance settings -> Get system log. Here is more documentation on what to add to your bash script, as well as a video that shows where to find the logs.