I’ve been creating EC2 instances on a one-off basis, which is great practice, but as I am wanting to learn how to use IaC methodologies, I wanted to explore creating a launch template.
First, I selected Launch Template from within the EC2 dashboard. I gave the template a name, selected the Amazon Linux x86 AMI image, and selected ts.micro for the instance type. For the security group, I created a new security group, allowing HTTP protocol on port 80.
The reason for allowing access to that port is that this server instance is going to be a web server. That’s seen in the subsequent configuration..
Under Advanced Details, I entered the following code:
#!/bin/bash
sudo dnf update
sudo dnf install httpd -y
sudo systemctl start httpd
sudo systemctl enable httpd
sudo chmod 777 /var/www/html
echo "welcome to my site!" > index.html
cp index.html /var/www/html
I saved the Launch Template, and once that had saved, I launched an instance using that template. The public IP address for that instance in this case was 54.224.72.137. I copied that and put it into the browser, and the web server displayed the “welcome to my site!” message as expected. Hooray!
