Day 2: Creating an EC2 Instance Template with User Data for Automated Service Installation
This blog illustrates how to create an EC2 instance template and use User Data to automate service installation during launch, simplifying deployments
What is an EC2 Template
AWS EC2 template is a pre-defined setup to configure an ec2 instance. you can make template of any instance running to save its current configurations to be used next time while launching another ec2 server.
Create a Template
Create a template of a running instance as shown below.
Give name and version for the template and you will find all settings will be same as the original running instance. Now, save the template by clicking create launch template. Keep in mind that a template will only save the state of the instance not the services running on it.
Launch instance from Template
Now, create a new instance from this template as shown below.
Select the template you want to choose to create ec2 instance. Here it will show only one as no other template or version is created.
Modifying Template
Go to the template created before and modify it to new version as v3.
If you want to install any service while creating ec2 instance, you can do so by writing script in ‘user data‘ under ‘advanced details’. To modify template to do so, a shell script is written and new version of template is created.
Now, create a new instance from this new template v3 and connect this new instance to find nginx is already installed here.
Don’t forget to open port 80 to see the nginx server running.
This blog covers everything about templates. I hope you find it helpful! Stay tuned for more insights on AWS services. Don’t forget to follow for more useful blogs. – Neha Bhardwaj