How to Setup Jenkins on AWS Using CloudFormation
- Mohammad Abu Mattar
- Cloud Computing , DevOps
- 11 Dec, 2022
- 04 Mins read
Introduction
In a previous blog post, we setup Jenkins on AWS using the AWS CLI (How to Install Jenkins on AWS EC2 Instance). In this blog post, we will be using CloudFormation to setup Jenkins on AWS. CloudFormation is a service that helps you model and set up your AWS resources so that you can spend less time managing those resources and more time focusing on your applications that run on AWS.
Prerequisites
- AWS CLI installed and configured
- IAM user with the following permissions:
- AmazonVPCFullAccess
- AmazonEC2FullAccess
- AmazonS3FullAccess
Create a CloudFormation
Step 1: Create a Key Pair
Create a key pair to access the EC2 instance via SSH.
Note: Store the key pair at a safe place. You will need it to access the EC2 instance via SSH.
Step 2: Create a CloudFormation Template
Create a file named jenkins-server.yml
and add the following content:
Step 3: Create a CloudFormation Stack
Now that you have created a template, you can create a stack using the AWS CLI.
Step 4: Check the Status of the Stack
You can check the status of the stack using the AWS CLI.
Step 5: Access the Jenkins Server
You can access the Jenkins server using the public IP address of the instance.
Connect to the Jenkins Server, and Setup Jenkins
Step 1: Connect to the Jenkins Server
Connect to the Jenkins server using SSH.
Step 6: Configure Jenkins
Connect to EC2 instance using SSH and run the following commands to configure Jenkins.
Copy the initial password and paste it in the Jenkins login page.
Select the recommended plugins and click on the Install button.
Create an admin user and click on the Save and Finish button.
Done! You have successfully setup Jenkins on AWS using CloudFormation.
Cleanup
You can delete the stack using the AWS CLI.
Conclusion
In this article, we have learned how to setup Jenkins on AWS using CloudFormation. We have also learned how to create a CloudFormation template and create a stack using the AWS CLI.