What is User Data In AWS?
How to use User Data?
Advantages of User Data?
AWS allows to run some commands/scripts at launch time of an instance which is known as user data. For example, you want to have certain packages installed or some configuration files to be present on the instance after the launch, user data is the thing you need. Whatever commands you specify in the user data gets executed and you get the stuff when instance is launched.
Let's try an example, Below is the user data which is creating a file and we are putting some content in it. set -x option will start the debugging mode and all the standard output will get logged in /var/log/user-data.log file, so after the instance is launched, you can see what all commands gets executed and which commands got failed.
What is User Data In AWS?
How to use User Data?
Advantages of User Data?
AWS allows to run some commands/scripts at launch time of an instance which is known as user data. For example, you want to have certain packages installed or some configuration files to be present on the instance after the launch, user data is the thing you need. Whatever commands you specify in the user data gets executed and you get the stuff when instance is launched.
Let's try an example, Below is the user data which is creating a file and we are putting some content in it. set -x option will start the debugging mode and all the standard output will get logged in /var/log/user-data.log file, so after the instance is launched, you can see what all commands gets executed and which commands got failed.
#!/bin/bash
# set debug mode set -x # output log of userdata to /var/log/user-data.log exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
# create and put some content in the file touch /home/ec2-user/created_by_userdata.txt ( cat << 'EOP' Hey there!!! EOP ) > /home/ec2-user/created_by_userdata.txt
You will get the option to put user data in "Configure Instance Details page" as shown below:
A great use-case for user data could be, bootstrapping autoscaled instance with chef. Here is the complete post explaining this use case.
0 comments:
Post a Comment