Day 52: Your CI/CD Pipeline on AWS - Part-3

Day 52: Your CI/CD Pipeline on AWS - Part-3

Welcome back to Day 52 of our 90DaysOfDevOps challenge! Today, we will dive deeper into setting up a Continuous Integration/Continuous Deployment (CI/CD) pipeline on AWS, specifically focusing on AWS CodeDeploy. In the previous blog post, we discussed the fundamentals of CI/CD and began exploring AWS services for building our pipeline. Today, we'll continue from where we left off and delve into the specifics of AWS CodeDeploy.

What is AWS CodeDeploy?

AWS CodeDeploy is a fully managed deployment service that automates software deployments to various compute services such as Amazon EC2 instances, AWS Lambda functions, and on-premises servers. It allows you to deploy your applications in a consistent and reliable manner, facilitating continuous delivery of updates.

Task-01: Deploying an index.html File on EC2 with Nginx Using CodeDeploy

Appspec.yaml File for CodeDeploy

The appspec.yaml file is a crucial component of the CodeDeploy deployment process. It defines the deployment lifecycle and specifies the actions to be taken at each stage of deployment. Below is a basic example of an appspec.yaml file for deploying a static website on an EC2 instance with Nginx:

version: 0.0
os: linux
files:
  - source: /
    destination: /usr/share/nginx/html
hooks:
  AfterInstall:
    - location: scripts/restart_nginx.sh
      timeout: 300
      runas: root

In this example:

  • files: Specifies the source and destination for the files to be deployed.

  • hooks: Defines the lifecycle event hooks. Here, AfterInstall hook is used to restart Nginx after deployment.

Setting Up CodeDeploy Agent

Before deploying using CodeDeploy, we need to set up the CodeDeploy agent on our EC2 instance. This agent facilitates communication between your EC2 instances and the CodeDeploy service.

Task-02: Adding Appspec.yaml File to CodeCommit Repository and Deployment Process

Now, let's integrate the appspec.yaml file into our CodeCommit repository and initiate the deployment process step by step:

  1. Add appspec.yaml to CodeCommit Repository:

    • Commit and push the appspec.yaml file to your CodeCommit repository.
  2. Configure CodeDeploy Deployment Group:

    • Log in to the AWS Management Console.

    • Navigate to the CodeDeploy service.

    • Create a new deployment group, specifying your EC2 instances and deployment settings.

  3. Initiate Deployment:

    • Select the application and deployment group you created.

    • Choose the revision (version) of your application.

    • Start the deployment process.

  4. Monitor Deployment:

    • Monitor the deployment process in the CodeDeploy console.

    • Check for any errors or issues during deployment.

By following these steps, you can successfully deploy your application using AWS CodeDeploy.

Conclusion

In this blog post, we explored AWS CodeDeploy and learned how to deploy a static website on EC2 instances using Nginx. We discussed the importance of the appspec.yaml file in defining deployment actions and walked through the steps to set up the CodeDeploy agent and initiate the deployment process. Stay tuned for more updates as we continue our journey through the 90DaysOfDevOps challenge!