How To Configure AWS CodeDeploy With Jenkins On AWS

We can install and configure AWS codedeploy agent with Jenkins integration. we need to install AWS codedeploy plugins in the Jenkins server to integrate. we also need to install codedeploy agent on the machine that will help us to deploy the code on the servers.

How To Configure AWS CodeDeploy With Jenkins On AWS Cloud

We have tried to deploy for the tomcat project using codedeploy with Jenkins integration. you need to start the code deploy agent on the machine then you can take the AMI of the server to launch the configuration.

Check Out: How To Install Microsoft SQL Server On Ubuntu 20.04

Step 1: We need to install the CodeDeploymentAgent on the server that will help you to deploy the code.

sudo yum install ruby
sudo yum install wget
cd /home/ec2-user

We need to change the “bucket name” and region in the above command. You can find the Code agent deployment reference.

Step 2: First of all, we need to create an “IAM role” where we have to attach the “S3 Full Access/Read Only” and “AmazonEC2RoleForAWSCodeDeploy” policies.

We have created a role with EC2-s3-role as shown below.

Step 3: We need to create an “AMI”  either of the running instance or fresh that will be used in the creation of Launch configuration in autoscaling.

Check Out: How To Install and Configure RDS Database On AWS Cloud

Go the “EC2” -> Click on “autoscaling” -> Click on “Launch configuration“.

Give it a name and select the “Custom AMI” that you have created.

Now you have to select your “instance type“. Click on “Choose instance type”.

In the additional configuration, you can also select the IAM role, Monitoring, EBS-optimised instance, and much more. It depends on your requirement.

You can “add volume” and it will use them at the time of scaling. I haven’t added any extra volume.

We can create a “new security group” or you can use the existing one. I have created a new one and allowed port 22 and 8080 for SSH and tomcat.

I will use the existing key here.

Finally, click on the Create “Launch Configuration”. We have created the launch configuration template as shown below.

Create the autoscaling group:

We need to create an autoscaling group where we will define the number of instances that should be launched using this group at the time of deployment.

Check Out: How To Send Tomcat Logs To S3 Bucket From EC2 Instance

Click on “Autoscaling Group”.

Give it a name.

In the drop-down section, select the template which you have created in launch configuration.

Click on “Next“. you can select which one you want.

Select your “network” where you want to launch it and click on “Next”.

If you want to enable “load balancing”, you can do this way otherwise don’t select it.

We can also apply the health check of a running instance. It will control ping 300 sec, if this doesn’t receive any response, it will launch the server according to your autoscaling policy.

This will automatically replace the failed instances.

If required, enable monitoring with cloudwatch.

Now we have to tell the group how many instances should be launched. You can change the minimum and maximum values.

Keep it default.

You can also configure the “SNS notification service”, you will receive the email notification.

We can give a tag to this group, review, and click on Create “auto-scaling group”.

You can see we have created the scaling group.

Check Out: How To Create Build Using AWS CodeBuild Service

Configuration of CodeDeploy:

Go to the service CodeDeploy -> Choose “Application”.

Give it any name for the “application“.

Once the application is created. We need to create a “deployment group”.

Give a deployment group name

Select a “Service role” that you have created.

You can select “deployment type” here.

Select your “autoscaling group” or other options.

Select these options in the drop-down

We can also select the “Load balancer” which we have created in the above steps.

how to configure aws codedeploy

You can create a trigger here that will use SNS services to send you an email.

aws codedeploy

We can also configure alarm settings.

jenkins deploy to aws ec2

You can select which options you want to check here.

aws codedeploy with jenkins

Now click on “Create deployment group” and it’s created.

how to deploy code using codedeploy

Open your deployment group and Click on “Create Deployment”.

codedeploy agent install

Select your “revision type” here and provide the S3 bucket path.

install codedeploy agent ec2 linux

Now Click on “Create Deployment” and it will start the deployment. It will use the application that is stored on the S3 bucket.

We also have to create a appsepec.yml file in your GitHub project root directory and define your tomcat path.

version: 0.0
os: linux

- source: ./
destination: /opt/apache-tomcat-8.5.35/webapps
overwrite: yes

Check Out: How To List Git Remote Branches of Repository From Github

Jenkins Integration With S3:

Now you have to integrate the setup with Jenkins using these how to integrate Jenkins with s3. This will keep the build on S3 storage and then the deployment group will automatically pick up the file from S3 location.

When you have configured codedeploy integration with Jenkins. you need to build a trigger from Jenkins’s job and the code deployment automatically starts to deploy the code on the server. It will pull the latest build from the S3 bucket.

Once the deployment is successful. Go to the “deploy” -> Click on “deployments”.

jenkins and codedeploy integration

You can also check the deployment steps in the cycle.

aws codedeploy configuration

You can also trigger the build from Jenkins setup then it will automatically start deployment here. 

Check Out: Create VPC Network Using AWS CLI From Windows CMD

If it’s not working, try to attach “EC2CodeDeployRole” on EC2 instance and restart the AWS codedeploy agent on the server.

Once you apply for the role, you also need to restart the agent on the server. We will give a build from Jenkins and it should start auto-deployment as shown above.

That’s it. jenkins and codedeploy integration aws install agent configure

Share on:

I'm the founder of Curious Viral. I hope this blog will provide you complete information about Linux Technology & I would like to share my technical knowledge with you which I have learned during this period.

Other Posts You May Like...

Leave a comment