X
    Categories: Blog

Automation of Application (Jenkins) Deployment & Configuration on AWS using CloudFormation

Any organization that wants to stay ahead of the competition needs to have an effective DevOps program. DevOps has paved the way for faster software development and deployment while assuring complete customer satisfaction through the seamless integration of the Development and Operations teams. The DevOps culture has altered how IT operates by uniting teams to accomplish crucial business objectives. DevOps is built on automation and continual improvement. It’s a step in the direction of a release pipeline that is more reliable and consistent, as well as automation and improved communication.

In Part 1 of this series, we have learned how applications can be installed, configured, and validated on AWS using Terraform. In this blog, we will use another IaC tool – CloudFormation, for the same purpose of targeting the Jenkins application.

It is unproductive to install and configure AWS resources manually. Additionally, it raises the possibility of configuration errors and inconsistencies, which can lead to problems and raise security risks. It also makes scaling or updating resources less effective.

We can streamline the AWS deployment procedure by using an IaC tool like CloudFormation. Our resource configurations can be defined once, then deployed as many times as necessary.

Our CloudFormation templates allow us to keep track of how we configure our resources and how we have changed over time. We can also swiftly and predictably update resources using change sets.

To have a completely scripted versioned architecture, we use CloudFormation. Everything, from the application to the virtual resources, is produced in the YAML script. As a result, we have total control over our AWS infrastructure and can be recreated whenever necessary.

Alternative methods of approaching IAC:

  • Terraform
  • Ansible

Why use CloudFormation?

CloudFormation offers to deploy Infrastructure as a Code, helps in readability and lift and shift deployments; Terraform for the purpose of orchestration and Ansible for configuration management. Ansible is a configuration management tool for automating system configuration and management.

Key Componenets:

Mappings: Mappings is for specifying conditional parameter values in our template. For instance, we might want to use a different AMI depending on the region our instance is running on. Mappings will enable us to switch AMIs depending on the region the instance is being created in.

Resources: Resources are the most vital part of the CloudFormation template. Inside the resource section, we define and configure our AWS components.

In addition, we have created the public subnet, and public route table and have attached the public subnet route table association for the creation of the EC2 instance.

You can create a security group and add rules that reflect the role of the instance that is associated with the security group.

Walkthrough

In this blog, we have followed the below steps:

  • Creating resources to build the infrastructure, including the Jenkins server
  • Accessing and unlocking the Jenkins server by using a groovy file
  • Creating a project and configuring the Jenkins plugin.

AWS CloudFormation UserData Template

CloudFormation parameters and resources can be referenced throughout the template. We do this using intrinsic functions, Fn::Base64, Fn::Join. These functions enable us to pass properties and resource outputs throughout our template – reducing the need for most hardcoded properties.

In this template, we are adding userdata script to install Java JDK and Jenkins on our EC2 instance.

To unlock and access the Jenkins server by using the groovy script in the userdata.

Install a new Jenkins plugin using CLI. We are installing a required jenkins plugin to create and build a job in the jenkins server.

Challenges faced while performing stack creation

  • Check the credentials while executing the command as it may cause an error in the YAML script.
  • If there is no value given or the alignment is wrong in the YAML script, you will get a not-well formatted error.
  • To avoid errors, check the alignment properly and then execute the whole script.
  • While performing the repository cloning, the git might cause an error.

Creating a Stack using a prepared template:

The way to create a CloudFormation template is either by using a pre-existing template or creating a template in the designer.

Creation of an EC2 Instance:

Creating an infrastructure code in main.yaml file with the specifications needed by executing the code with cloudformation and then the EC2 instance will be launched.

After creating a stack, we are launching the EC2 instance and Jenkins server through the CloudFormation template. We are validating that Jenkins was installed on the EC2 instance through the Jenkins pipeline.

References: https://github.com/Satheesrajv/CloudFormation-blog.git

If you have any questions or suggestions, please reach out to us at contactus@1cloudhub.com

Written By:  Naveen Kumar , Sathees Raj V, Rakesh Kumar K, and Umashankar N

Published On: July 05, 2022

Sharing is caring!

View Comments (0)

Comments are closed.