amazon-web-servicesamazon-ec2amazon-amiec2-userdata

The AWS user data option isn't functioning


Using the AWS console, I'm launching an instance using a custom AMI. A few XML files need to be updated as part of the system initialization. Although I entered the user data, it doesn't appear to be working. Even though I tried simple things like echoing in a file, it still doesn't work.

[root@ip-xx-xx-xx-xx ~]# curl -s http://169.254.169.254/latest/user-data
#!/bin/bash
echo "Shiv" >  /tmp/check1.txt
echo "all" > check.txt[root@ip-172-31-40-190 ~]# timed out waiting for input: auto-logout

Nothing related to cloud keyword is present in /var/log/message:

grep -inr "cloud" /var/log/messages 

User data entered

It even doesn't have the file /var/log/cloud-init-output.log. What am I missing in this situation?


Solution

  • It appears that you are Importing a VM as an image using VM Import/Export - VM Import/Export. As a result, your instance does not have cloud-init installed.

    cloud-init is a utility that will runs scripts at launch:

    Cloud images are operating system templates and every instance starts out as an identical clone of every other instance. It is the user data that gives every cloud instance its personality and cloud-init is the tool that applies user data to your instances automatically.

    When you boot an Amazon EC2 instance, it runs an operating system. The operating system is responsible for running processes on the instance, responding to scripts, command-lines, etc. It's just like any normal computer. The process that runs scripts at launch is called cloud-init.

    If cloud-init is installed on an EC2 instance then it will look in the User Data nd run the script once per instance ID. It can also run in other situations depending on configuration.

    cloud-init is installed on Amazon Linux, Unbuntu and some other AMIs.

    Since you are creating your own AMI from an external VM, you will need to install cloud-init to make User Data scripts run on first boot.

    A bit of history... User Data was originally just a way to 'pass some information' to the instance (hence the name 'user data'). It was Canonical who first conceived of the idea that it would be possible to pass a script via User Data. The created cloud-init and it has become a standard for many cloud computing platforms.