DEV Community

Cover image for Creating a Continuous Delivery Pipeline in AWS (Hands-On)
sipsdaoracle
sipsdaoracle

Posted on

Creating a Continuous Delivery Pipeline in AWS (Hands-On)

This week, I decided to dive deeper into the world of DevOps and SRE. As I was exploring various resources, I stumbled upon a hands-on AWS module focusing on Creating Continuous Delivery Pipelines. Recognizing the importance of this topic and its relevance in modern software development, I felt compelled to delve into it as a starting point for my journey.

For those unfamiliar with the concept, continuous deployment is a method that enables automatic deployment of code revisions to a production environment, eliminating the need for manual approval from developers. This automation streamlines the software release process and enhances efficiency.

Throughout this tutorial, I gained valuable insights into the creation of a continuous delivery pipeline. I learned how to set up a system that automatically deploys a sample web application whenever changes are made to the source code. This hands-on experience provided a practical understanding of the mechanisms behind continuous delivery and its significance in modern software development practices.

Everything done in this tutorial is Free Tier eligible.

Prerequisite

  • An AWS account
  • A GitHub account
  • Git installed on your computer

What I learned from this:

  1. Set up a GitHub repository for the application
    code

  2. Create an AWS Elastic Beanstalk environment
    to deploy the application

  3. Configure AWS CodeBuild to build the source
    code from GitHub

  4. Use AWS CodePipeline to set up the continuous
    delivery pipeline with source, build, and deploy
    stages

Visual representation of End Architecture:

Image description

Task 1: Set Up Git Repo

Step 1: Fork a GitHub repository to create a new one

Image description

Step 2: Store code and metadata in GitHub Repository(Push Code)

  • Go to the repository, click on the green Code button and copy the url of the repo to clone it.

  • Open the terminal or Bash platform of your choice and enter the following command and paste the URL

git clone https://github.com/YOUR-USERNAME/aws-elastic-beanstalk-express-js-sample
Image description

  • In the new folder there is a file named app.js. Open app.js Change the message in line 5 to say something other than "Hello World!" and save the file.

  • Go to the folder created with the name aws-elastic-beanstalk-express-js-sample/ and Commit the change with the following commands:

git add app.js
git commit -m "change message"

  • Push the changes by entering the following command:

git push

Step 3: Test the changes

  • On Github under Repositories, select the one named aws-elastic-beanstalk-express-js-sample

  • Choose the app.js file. The contents of the file, including your change, should be displayed

Image description

Task 2: Deploy a Web App

Step 1: Configure and create an AWS Elastic Beanstalk environment

  • open the AWS Elastic Beanstalk console and click on Create Application button

Image description

  • under the heading Application name, enter DevOpsGettingStarted

Image description

  • Select Node.js from the Platform dropdown menu.

Image description

  • Ensure that sample application is selected.

Image description

  • Click create application button

Once you see the green checkmark, you have successfully created an AWS Elastic Beanstalk application and deployed it to an environment.

Step 2: Test the web app

  • To test your sample web app, select the link under the name of your environment.

Image description

Once the test has completed, a new browser tab should open with a webpage congratulating you!

We will use this environment and our continuous delivery pipeline to deploy the Hello World! web app we created in the previous module.

Task 3:Create Build Project

Step 1: Create a build project with AWS CodeBuild

  • Open the AWS CodeBuild console and choose the create project button.

Image description

  • In the Project name field, enter Build-DevOpsGettingStarted.

Image description

  • Select GitHub from the Source provider dropdown menu, Connect using OAuth and Choose the white Connect to GitHub button.

  • Choose the green Authorize aws-codesuite button and Enter your GitHub password.

  • Choose the Confirm button and Select Repository in my GitHub account.

  • Enter aws-elastic-beanstalk-express-js-sample in the search field.

  • Select the repo you forked

Image description

  • Confirm that Managed Image is selected.

  • Select Amazon Linux 2 from the Operating system dropdown menu.

  • Select Standard from the Runtime(s) dropdown menu.

  • Select aws/codebuild/amazonlinux2-x86_64-standard:3.0 from the Image dropdown menu.

  • Confirm that Always use the latest image for this runtime version is selected for Image version.

  • Confirm that Linux is selected for Environment type.

  • Confirm that New service role is selected.

Image description

Step 2: Create a Buildspec file for the project

  • Select Insert build commands.
  • Choose Switch to editor.
  • Replace the Buildspec in the editor with the code below: version: 0.2 phases: build: commands: - npm i --save artifacts: files: - '**/*'

Image description

Create build project button. You should now see a dashboard for your project.

Step 3: Test the CodeBuild Project

  • Choose the Start build button to configure the build process

Image description

  • Wait for the build to complete. After a couple minutes, a green checkmark and a Succeeded message confirming the build worked.

We have created a build project on AWS CodeBuild to run the build process of the Hello World! web app from our GitHub repository. We will be using this build project as the build step in our continuous delivery pipeline.

Task 4: Create Continuous Delivery Pipeline

Step 1: Create a new Pipeline

  • Open the AWS CodePipeline console and click the Create pipeline button

Image description

  • In the Pipeline name field, enter Pipeline-DevOpsGettingStarted.

  • Confirm that New service role is selected.

  • Choose the Next button.

Image description

Step 2: Configure a source stage using your GitHub repo

  • Select GitHub version 1 from the Source provider dropdown menu.

  • Choose Connect to GitHub button.

  • Choose Authorize aws-codesuite button.

  • From the Repository dropdown, select the repo you created.

Image description

  • Select main from the branch dropdown menu.
  • Confirm that GitHub webhooks is selected.
  • Choose the Next button.

Image description

Step 3: Configure the build stage

  • From the Build provider dropdown menu, select AWS
    CodeBuild.

  • Under Region confirm that the US West (Oregon)
    Region is selected.

  • Select Build-DevOpsGettingStarted under Project
    name.

Image description

  • Choose the Next button.

Step 4: Configure Deploy stage

  • Select AWS Elastic Beanstalk from the Deploy
    provider dropdown menu.

  • Under Region, confirm that the US West (Oregon)
    Region is selected.

  • Select the field under Application name and
    confirm you can see the app DevOpsGettingStarted

  • Select DevOpsGettingStarted-env from the
    Environment name textbox.

  • Choose the Next button.

Image description

You will now see a page where you can review the pipeline configuration.

  • Choose the Create pipeline button.

Step 5: Watch the pipeline execution

  • Once the Deploy stage has switched to green and it says Succeeded, choose AWS Elastic Beanstalk.
    Image description

  • A new tab listing your AWS Elastic Beanstalk environments will open.

  • Select the URL in the Devopsgettingstarted-env row.

Image description

  • You should see a webpage with a white background and the text you included in your GitHub commit

Image description

We have created a continuous delivery pipeline on AWS CodePipeline with three stages: source, build, and deploy.
The source code from the GitHub repo is part of the source stage. That source code is then built by AWS CodeBuild in the build stage.
Finally, the built code is deployed to the AWS Elastic Beanstalk environment.

Task 5:Finalize Pipeline and Test

Step 1: Create Review Stage in Pipeline

  • Open the AWS CodePipeline console

  • Select Pipeline-DevOpsGettingStarted

  • Choose the Edit button and click the Add stage button between the Build and Deploy stages.

Image description

  • In the Stage name field, enter Review.
  • Choose the Add stage button.
  • In the Review stage, choose the Add action group button.

Image description

  • Under Action name, enter Manual_Review.
  • From the Action provider dropdown, select Manual approval.
  • Confirm that the optional fields have been left blank. Choose the Done button. Choose the Save button at the top of the page. Choose the orange Save button to confirm the changes. You will now see your pipeline with four stages: Source, Build, Review, and Deploy.

Conclusion:

In summary, this tutorial has equipped you with the knowledge to set up a continuous delivery pipeline on AWS using services like CodePipeline, Elastic Beanstalk, and CodeBuild. By automating the deployment process for a sample web application, you've learned the benefits of continuous delivery, including faster release cycles and improved efficiency.

As you delve deeper into DevOps and SRE practices, remember to regularly review and optimize your pipelines to meet evolving organizational needs. By embracing automation and continuous improvement, you'll be better positioned to respond to customer feedback and market demands effectively.

I hope this tutorial has empowered you to embark on your continuous delivery journey with confidence. Happy coding and deploying!

Top comments (0)