Question

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'?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top