Table of contents
An EC2 instance is like a virtual computer in the cloud. It's where you can run your software and do tasks without needing a physical computer. Just like you use your laptop, an EC2 instance lets you use a computer that's online and ready to work whenever you need it.
Before you start
AWS EC2 setup knowledge is required.
An excellent Internet connection.
If you're unsure about setting up an AWS EC2 Instance, you can find guidance in my blog post. Simply click here to read more.
Launching Template
Head to the AWS Management Console, and in the search bar, choose EC2.
Following that, choose Launch Templates from the instances section and then click on the Create Launch template button.
Provide a name and description for the template.
Choose the operating system (OS) image that you're comfortable with. In my case, I'm selecting Ubuntu.
Go for the t2.micro instance type to avoid bills.
Choose a key that you'll use to SSH into the instance. If you don't have a key, create a new one and then select it.
In the network settings, stick with the default VPC and subnet. Choose the option to Create a security group.
Provide a name and description for the security group.
Click the "Add security group rule" button and add two security groups as depicted below. This is crucial because we'll be automating the installation of Jenkins and NGINX using this template, and these security groups will enable us to access them.
Choose "Advanced Details" and navigate to the last section called "User data."
In "User data," enter a script that automates tasks on instance creation. This makes installations happen automatically when using this template.
Paste the following script to automatically install Jenkins and nginx on your instance.
#!/bin/bash #nginx-installation sudo apt-get update -y sudo apt install nginx -y sudo systemctl start nginx sudo systemctl enable nginx echo "This is automated by a Launch Template" > /var/www/html/index.html #jenkins-installation sudo apt-get update -y sudo apt install openjdk-17-jre -y sudo curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee \ /usr/share/keyrings/jenkins-keyring.asc > /dev/null echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \ https://pkg.jenkins.io/debian-stable binary/ | sudo tee \ /etc/apt/sources.list.d/jenkins.list > /dev/null sudo apt-get update -y sudo apt-get install jenkins -y
Finally, click the "Create launch template" button.
Navigate to the instances section and initiate an instance launch using the template.
Wait for the instance to initialize, and then check if your services are installed by accessing them.
It's evident that both Jenkins and nginx have been successfully installed and accessed.
Conclusion
With this template, you can automate the installation of Jenkins and Nginx. You'll be able to create multiple instances effortlessly with just a single click.