I have see all the document on the AWS, but I still don't konw who trigger the user-data after the operation system is installed. Is the startup script automatically run the user-data(and download the content of user-data) or the AWS server will 'call' the user-data on this instance according to whether the user input the user-data. What is going on 'under the hood'?
2 Answers
Whether or not an instance runs user-data scripts is entirely up to the AMI and the software it comes with. Some AMIs do, some don't, and it's up to you to read the provider's documentation or test it for yourself.
Ubuntu AMIs and Amazon Linux AMIs have the cloud-init software package installed. This software runs various processes on your instance (server) when it boots. One of the processes checks to see if it is the first the the instances has ever booted and if the user-data starts with the characters "#!". If both of these are true, then the user data is run on the instance.

- 22,089
- 5
- 66
- 75
-
Eric, I have another question: Does some of the AMIs doesn't have user-data tools at all? and those have user-data tools will startup automatically in any case? – SoYoung Mar 06 '13 at 07:27
-
@SoYoung: If an AMI does not include software to process user-data, then any user-data script will simply be ignored. – Eric Hammond Mar 08 '13 at 21:56
All machine metadata are crawled from medata server by cloud-init, which handles early initialization of a cloud instance. You can find details of that operation in /var/log/cloud-init.log. ie.
...
2013-10-14 21:06:50,504 - DataSourceEc2.py[DEBUG]: removed the following from metadata urls: ['http://instance-data:8773']
2013-10-14 21:06:50,596 - DataSourceEc2.py[DEBUG]: Using metadata source: 'http://169.254.169.254'
2013-10-14 21:06:53,449 - DataSourceEc2.py[DEBUG]: crawl of metadata service took 2s
...
Metada server recognize client and serve him proper data. If you call
curl http://169.254.169.254/latest/user-data
from cloud machine, you will get user-data passed by user.

- 1,973
- 1
- 12
- 10