Reason why AWS EC2 user data feature is important!
When we create any EC2 instance in AWS, it also provides one field called user data. Why is that and how is it useful?
Let's get into practical approach and understand.
Case 1: Suppose we have to create one instance where we want to run our CI tool (say jenkins). To run jenkins, we have to connect instance with SSH and then run commands manually.
Case 2: Suppose we have to create 10 instances where we have to again run jenkins in all machine. What will we do? Again run same commands manually in all machine 10 times?
Well, answer is YES if you don't utilize user data field.
AWS provides feature where you can specify more than 1 instance to launch and all the instances will launch with the same configuration. If we provide our script in user data field then it will run/install desired programs/tools/softwares in all machine along initiation of instances.
Always start your user data script with shebang line telling which shell to use to run commands. This is a safe practice as sometimes your script can fail if you miss this.
I have created one github repository where I tried storing user data script for some important tools and softwares. In case you want to contribute to that repo, create a PR and I will merge it.
Github Repository :: https://github.com/mrburnwal/ec2-user-data
Thanks.