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.
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 wget https://bucket-name.s3.region-identifier.amazonaws.com/latest/install
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.
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.
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.
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.
You can create a trigger here that will use SNS services to send you an email.
We can also configure alarm settings.
You can select which options you want to check here.
Now click on “Create deployment group” and it’s created.
Open your deployment group and Click on “Create Deployment”.
Select your “revision type” here and provide the S3 bucket path.
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 files: - source: ./ destination: /opt/apache-tomcat-8.5.35/webapps overwrite: yes
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”.
You can also check the deployment steps in the cycle.
You can also trigger the build from Jenkins setup then it will automatically start deployment here.
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