Introduction
This project implements a Continuous Delivery (CD) pipeline using AWS CodePipeline, AWS CodeBuild, and AWS Elastic Beanstalk to automate deployments. The setup provides a structured approach to code deployment, enhancing reliability and minimizing manual processes—ideal for agile development teams aiming for efficient, high-frequency deployments.
Tech Stack
AWS CodePipeline: Manages the entire deployment flow, coordinating the build, test, and deployment stages.
AWS CodeBuild: Automates the building and testing of code, ensuring that each change is thoroughly validated before deployment.
AWS Elastic Beanstalk: Manages the deployment of the web application, ensuring it is hosted in a high-availability, scalable environment.
Amazon EC2 with Auto Scaling: Ensures scalable, fault-tolerant infrastructure to support application load, with ALB (Application Load Balancer) for even traffic distribution.
Prerequisites
AWS Account: Required for configuring the CD pipeline and associated services.
Code Repository: A source code repository such as GitHub or CodeCommit that integrates with CodePipeline.
Basic CI/CD Knowledge: Familiarity with the principles of continuous integration and continuous delivery.
AWS CLI: To facilitate configuration and command-line management.
Problem Statement or Use Case
Problem: Manually deploying updates to web applications is error-prone, time-consuming, and can lead to inconsistent deployment practices, especially in fast-paced development environments.
Solution: The Continuous Delivery Pipeline ensures that each code change is automatically built, tested, and deployed to a managed environment, reducing manual intervention. This setup allows developers to push code more frequently, get faster feedback, and minimize deployment risks.
Real-World Relevance: In production settings, a CD pipeline is crucial for agile teams who need reliable, frequent deployments without impacting application uptime or performance. This project demonstrates how AWS can automate and manage application deployments, making it ideal for high-availability and fast-paced development scenarios.
Architecture Diagram
Component Breakdown
Code Repository: A source control repository (GitHub or CodeCommit) triggers the pipeline when new code is committed, enabling continuous integration.
AWS CodePipeline: Automates the entire CI/CD process, orchestrating each stage from source to build to deployment.
AWS CodeBuild: Builds and tests the code. CodeBuild compiles, runs unit tests, and verifies the application to ensure it is ready for deployment.
AWS Elastic Beanstalk: Deploys the built application onto a highly available environment with Auto Scaling capabilities, which provides a robust infrastructure layer for the application.
Step-by-Step Implementation
Module 1: Set Up Git Repo
Fork the starter repo
- This tutorial assumes you have an existing GitHub account and Git installed on your computer. If you don’t have either of these two installed, you can follow these step-by-step instructions.
In a new browser tab, navigate to GitHub and make sure you are logged into your account.
In that same tab, open the aws-elastic-beanstalk-express-js-sample repo.
Choose the white Fork button on the top right corner of the screen. Next, you will see a small window asking you where you would like to fork the repo.
Verify it is showing your account and choose Create a fork. After a few seconds, your browser will display a copy of the repo in your account under Repositories.
Push a change to your new repo
Go to the repository and choose the green Code button near the top of the page.
To clone the repository using HTTPS, confirm that the heading says Clone with HTTPS. If not, select the Use HTTPS link.
Choose the white button with a clipboard icon on it (to the right of the URL).
If you’re on a Mac or Linux computer, open your terminal. If you’re on Windows, launch Git Bash.
-
In the terminal or Bash platform, whichever you are using, enter the following command and paste the URL you just copied in Step 2 when you clicked the clipboard icon. Be sure to change “YOUR-USERNAME” to your GitHub username. You should see a message in your terminal that starts with Cloning into. This command creates a new folder that has a copy of the files from the GitHub repo.
git clone https://github.com/YOUR-USERNAME/aws-elastic-beanstalk-express-js-sample
In the new folder there is a file named app.js. Open app.js in your favorite code editor.
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 local changes to the remote repo hosted on GitHub with the following command. Note that you need to configure Personal access tokens (classic) under Developer Settings in GitHub for remote authentication.
git push
Test your changes
In your browser window, open GitHub.
In the left navigation panel, 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.
Application architecture
Here is what our architecture looks like right now:
We have created a code repository containing a simple web app. We will be using this repository to start our continuous delivery pipeline. It’s important to set it up properly so we push code to it.
Module 2: Deploy Web App
Implementation
Configure an AWS Elastic Beanstalk app
In a new browser tab, open the AWS Elastic Beanstalk console.
Choose the orange Create Application button.
Choose Web server environment under the Configure environment heading.
In the text box under the heading Application name, enter DevOpsGettingStarted*.*
In the Platform dropdown menu, under the Platform heading, select Node.js . Platform branch and Platform version will automatically populate with default selections.
Confirm that the radio button next to Sample application under the Application code heading is selected.
Confirm that the radio button next to Single instance (free tier eligible) under the Presets heading is selected.
Select Next.
On the Configure service access screen, choose Use an existing service role for Service Role.
For EC2 instance profile dropdown list, the values displayed in this dropdown list may vary, depending on whether you account has previously created a new environment.
Choose one of the following, based on the values displayed in your list.
If aws-elasticbeanstalk-ec2-role displays in the dropdown list, select it from the EC2 instance profile dropdown list.
If another value displays in the list, and it’s the default EC2 instance profile intended for your environments, select it from the EC2 instance profile dropdown list.
If the EC2 instance profile dropdown list doesn’t list any values to choose from, expand the procedure that follows, Create IAM Role for EC2 instance profile.
Complete the steps in Create IAM Role for EC2 instance profile to create an IAM Role that you can subsequently select for the EC2 instance profile. Then, return back to this step.
Now that you’ve created an IAM Role, and refreshed the list, it displays as a choice in the dropdown list. Select the IAM Role you just created from the EC2 instance profile dropdown list.
- Choose Skip to Review on the Configure service access page.
This will select the default values for this step and skip the optional steps.
The Review page displays a summary of all your choices.
Choose Submit at the bottom of the page to initialize the creation of your new environment.
While waiting for deployment, you should see:
A screen that will display status messages for your environment.
After a few minutes have passed, you will see a green banner with a checkmark at the top of the environment screen.
Once you see the banner, you have successfully created an AWS Elastic Beanstalk application and deployed it to an environment.
Test your web app
- To test your sample web app, select the link under the name of your environment.
- 2. Once the test has completed, a new browser tab should open with a webpage congratulating you!
Application architecture
Now that we are done with this module, our architecture will look like this:
We have created an AWS Elastic Beanstalk environment and sample application. We will be using this environment and our continuous delivery pipeline to deploy the Hello World! web app we created in the previous module.
Module 3: Create Build Project
Configure the AWS CodeBuild project
In a new browser tab, open the AWS CodeBuild console.
Choose the orange Create project button.
In the Project name field, enter Build-DevOpsGettingStarted.
Select GitHub from the Source provider dropdown menu.
Confirm that the Connect using OAuth radio button is selected.
Choose the white Connect to GitHub button. A new browser tab will open asking you to give AWS CodeBuild access to your GitHub repo.
Choose the green Authorize aws-codesuite button.
Enter your GitHub password.
Choose the orange Confirm button.
Select Repository in my GitHub account.
Enter aws-elastic-beanstalk-express-js-sample in the search field.
Select the repo you forked in Module 1. After selecting your repo, your screen should look like this:
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.
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:
- '*/'- Choose the orange Create build project button. You should now see a dashboard for your project.
Test the CodeBuild project
Choose the orange Start build button. This will load a page to configure the build process.
Confirm that the loaded page references the correct GitHub repo.
Choose the orange Start build button.
Wait for the build to complete. As you are waiting you should see a green bar at the top of the page with the message Build started, the progress for your build under Build log, and, after a couple minutes, a green checkmark and a Succeeded message confirming the build worked.
Application architecture
Here’s what our architecture looks like now:
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, which we will create in the next module.
Module 4: Create Delivery Pipeline
Create a new pipeline
In a browser window, open the AWS CodePipeline console.
Choose the orange Create pipeline button. A new screen will open up so you can set up the pipeline.
In the Pipeline name field, enter Pipeline-DevOpsGettingStarted.
Confirm that New service role is selected.
Choose the orange Next button.
Configure the source stage
Select GitHub version 1 from the Source provider dropdown menu.
Choose the white Connect to GitHub button. A new browser tab will open asking you to give AWS CodePipeline access to your GitHub repo.
Choose the green Authorize aws-codesuite button. Next, you will see a green box with the message You have successfully configured the action with the provider.
From the Repository dropdown, select the repo you created in Module 1.
Select main from the branch dropdown menu.
Confirm that GitHub webhooks is selected.
Choose the orange Next button.
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.
Choose the orange Next button.
Configure the 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 created in Module 2.
Select DevOpsGettingStarted-env from the Environment name textbox.
Choose the orange Next button. You will now see a page where you can review the pipeline configuration.
Choose the orange Create pipeline button.
Watch first pipeline execution
- While watching the pipeline execution, you will see a page with a green bar at the top. This page shows all the steps defined for the pipeline and, after a few minutes, each will change from blue to green.
Once the Deploy stage has switched to green and it says Succeeded, choose AWS Elastic Beanstalk. A new tab listing your AWS Elastic Beanstalk environments will open.
Select the URL in the Devopsgettingstarted-env row. You should see a webpage with a white background and the text you included in your GitHub commit in Module 1.
Application architecture
Here’s what our architecture looks like now:
We have created a continuous delivery pipeline on AWS CodePipeline with three stages: source, build, and deploy. The source code from the GitHub repo created in Module 1 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 created in Module 3.
Module 5: Finalize Pipeline and Test
Create a review stage in pipeline
Open the AWS CodePipeline console.
You should see the pipeline we created in Module 4, which was called Pipeline-DevOpsGettingStarted. Select this pipeline.
Choose the white Edit button near the top of the page.
Choose the white Add stage button between the Build and Deploy stages.
In the Stage name field, enter Review.
Choose the orange Add stage button.
In the Review stage, choose the white Add action group button.
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 orange Done button.
Choose the orange 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.
Push a new commit to your repo
In your favorite code editor, open the app.js file from Module 1.
Change the message in Line 5.
Save the file.
Open your preferred Git client.
Navigate to the folder created in Module 1.
-
Commit the change with the following commands:
git add app.js
git commit -m "Full pipeline test"- Push the local changes to the remote repo hosted on GitHub with the following command:
git push
Monitor the pipeline and manully approve the change
Navigate to the AWS CodePipeline console.
Select the pipeline named Pipeline-DevOpsGettingStarted. You should see the Source and Build stages switch from blue to green.
When the Review stage switches to blue, choose the white Review button.
Write an approval comment in the Comments textbox.
Choose the orange Approve button.
Wait for the Review and Deploy stages to switch to green.
Select the AWS Elastic Beanstalk link in the Deploy stage. A new tab listing your Elastic Beanstalk environments will open.
Select the URL in the Devopsgettingstarted-env row. You should see a webpage with a white background and the text you had in your most recent GitHub commit.
- Congratulations! You have a fully functional continuous delivery pipeline hosted on AWS.
Application architecture
With all modules now completed, here is the architecture of what you built:
We have used AWS CodePipeline to add a review stage with manual approval to our continuous delivery pipeline. Now, our code changes will have to be reviewed and approved before they are deployed to AWS Elastic Beanstalk.
Clean up resources
Delete AWS Elastic Beanstalk application
In a new browser window, open the AWS Elastic Beanstalk Console.
In the left navigation menu, click on “Applications.” You should see the “DevOpsGettingStarted” application listed under “All applications.”
Select the radio button next to “DevOpsGettingStarted.”
Click the white dropdown “Actions” button at the top of the page.
Select “Delete application” under the dropdown menu.
Type “DevOpsGettingStarted” in the text box to confirm deletion.
Click the orange “Delete” button.
Delete pipeline in AWS CodePipeline
In a new browser window, open the AWS CodePipeline Console.
Select the radio button next to “Pipeline-DevOpsGettingStarted.”
Click the white “Delete pipeline” button at the top of the page.
Type “delete” in the text box to confirm deletion.
Click the orange “Delete” button.
Delete pipeline resources from Amazon S3 bucket
In a new browser window, open the Amazon S3 Console.
You should see a bucket named “codepipeline-us-west-2” followed by your AWS account number. Click on this bucket. Inside this bucket, you should see a folder named “Pipeline-DevOpsGettingStarted.”
Select the checkbox next to the “Pipeline-DevOpsGettingStarted” folder.
Click the white “Actions” button from the dropdown menu.
Select “Delete” under the dropdown menu.
Click the blue “Delete” button.
Delete build project in AWS CodeBuild
In a new browser window, open the AWS CodeBuild Console.
In the left navigation, click on “Build projects” under “Build.” You should see the “Build-DevOpsGettingStarted” build project listed under “Build project.”
Select the radio button next to “Build-DevOpsGettingStarted.”
Click the white “Delete build project” button at the top of the page.
Type “delete” in the text box to confirm deletion.
Click the orange “Delete” button.
Congratulations!
You successfully built a continuous delivery pipeline on AWS! As a great next step, dive deeper into specific AWS technologies and take your application to the next level.
Challenges Faced and Solutions
Deployment Failures Due to Environment Variables: At times, missing environment variables caused builds to fail.
Solution: Ensured that the required environment variables were securely stored in Elastic Beanstalk and made accessible to the application during deployment.
CodePipeline Integration with External Repositories: Faced issues when integrating CodePipeline with GitHub.
Solution: Configured OAuth permissions carefully and verified GitHub webhook functionality to trigger pipeline events.
Conclusion
The project demonstrates an efficient AWS Continuous Delivery pipeline that automates deployments from commit to production. By integrating CodePipeline, CodeBuild, and Elastic Beanstalk, development teams can focus on code quality and agility, resulting in faster releases and robust application performance.
Explore my GitHub repository.
Shubham Murti — Aspiring Cloud Security Engineer | Weekly Cloud Learning !!
Top comments (0)