AWS Certified Developer - Associate
AWS CICD Developer Tools
CodePipeline Demo
This guide explains how to set up your first pipeline in CodePipeline, which automatically deploys an application to AWS Elastic Beanstalk when changes are pushed to a CodeCommit repository.
Below you will find detailed steps, technical diagrams, and code snippets to help you through the process.
Deploying Your Application to Elastic Beanstalk
Begin by downloading a simple demo application (e.g., the nodejs.zip file) from the AWS Elastic Beanstalk documentation page under tutorials and samples.
Follow these steps once you have the demo application:
Create an Application
Log in to the AWS Elastic Beanstalk console and create a new application, naming it web app.Create Environments
Set up two environments: one for development and one for production.Development Environment
Click on "Create environment" and select the web server environment type. Name this environmentwebapp-dev
. Upload your application code by selecting the nodejs.zip file, then choose Node.js as the platform. For cost efficiency, configure the environment with a single instance.Production Environment
Create another environment calledwebapp-env-prod
. Choose Node.js as the platform and specify the existing application version (v1) instead of uploading a new file. Ensure the correct EC2 role and key pair are selected.
Verify Deployment
After a few minutes, confirm that both environments are successfully deployed by checking the URLs provided in the Elastic Beanstalk dashboards.Production Environment Dashboard
Development Environment Dashboard
Setting Up the CodeCommit Repository
Next, set up a CodeCommit repository to store your application code, which will be tied into CodePipeline.
Create the Repository
Navigate to the CodeCommit service and create a repository named webapp.Push the Code
Initialize your local Git repository, add your source files, commit your changes, and push to the remote repository. Replace the remote URL as needed.Tip
You might see warnings about line endings (LF vs. CRLF); these warnings can be safely ignored.
echo "# webapp2" >> README.md git init git add README.md git commit -m "first commit" git branch -M main git remote add origin https://github.com/Sanjeev-Thiyagarajan/webapp2.git git push -u origin main
Refresh the CodeCommit page after pushing to verify that all files are present.
Configuring CodePipeline
Now that your application and repository are set up, configure CodePipeline to automate your deployment process.
Create a New Pipeline
Open the CodePipeline service page and create a new pipeline named web app pipeline. Select the latest pipeline version to take advantage of advanced execution features, including supersede and queued modes.Service Role & Artifact Store
Create a new service role for the pipeline and use the default S3 artifact store settings unless you need custom configurations.
Configure the Source Stage
Select CodeCommit as the source provider, choose the webapp repository, and select themain
branch. For change detection, use CloudWatch events or periodic checks as recommended.Skip the Build Stage
Since this demo focuses on deploying to Elastic Beanstalk using CodeDeploy, skip the build stage. (Future demos may include integration with CodeBuild or Jenkins.)Configure the Deploy Stage
Set up the deployment action to deploy your application to Elastic Beanstalk:- Choose Elastic Beanstalk as the deployment provider.
- Select the application web app and the development environment
webapp-dev
.
Review and Create the Pipeline
Review your configuration settings and create the pipeline. It will automatically:- Pull code from CodeCommit in the source stage.
- Deploy the code to Elastic Beanstalk in the deploy stage.
Examine Pipeline Details
In the CodePipeline interface, you can view:- Source commit IDs
- Input and output artifacts
- Deployment details
Your S3 artifact store contains the zipped artifacts.
Triggering Pipeline Executions with Code Changes
Demonstrate how pipeline automation works by modifying your application code in CodeCommit and reviewing the updated deployment process.
Make a Code Change
Edit theindex.html
file in CodeCommit (for example, change the text from “congratulations” to “this is version two”) and commit your changes.Observe the Pipeline Execution
After committing, open the CodePipeline console to see the new execution:- The source stage will detect the new commit.
- The deploy stage will update the development environment with the modified application.
Verify the Change on Elastic Beanstalk
Refresh the development environment URL to ensure that the application now displays version two.
Enhancing the Pipeline with a Production Deployment Stage
Improve your deployment process by adding a production stage that includes a manual approval step for enhanced security.
Modify the Pipeline
In the CodePipeline console, add a new stage calleddeploy prod
.Add a Manual Approval Action
Within thedeploy prod
stage, insert an action group for manual approval. For example, label this action leadership approval. This step requires team lead or management approval before proceeding with production deployment.Deploy to Production
Following the manual approval, add an action to deploy the code to the production environment using Elastic Beanstalk. Configure the action with:- Input artifact: the same artifact from the previous stage.
- Environment: production (
prod
).
Test the Pipeline Flow
To test, modify theindex.html
file in CodeCommit (for example, update the text to “this is version three”) and commit the changes. The pipeline will then:- Update the development environment automatically.
- Pause at the production stage for manual approval.
Once approved, the pipeline will deploy the updated code to the production environment.
Final Verification
After manual approval and deployment, verify in Elastic Beanstalk that the production environment is running version three of the application.You can inspect the deployed HTML code:
<!DOCTYPE html> <html> <head> <title>Elastic Beanstalk</title> <style> body { color: #ffffff; font-family: Arial, sans-serif; font-size: 14px; -moz-transition-property: text-shadow; -moz-transition-duration: 4s; -webkit-transition-property: text-shadow; -webkit-transition-duration: 4s; text-shadow: none; } body.blurry { text-shadow: #fff 0px 0px 25px; } .linkColumn, .linksColumn { padding: 2em; } .textColumn { position: absolute; } </style> </head> </html>
Once the production deployment is confirmed, the pipeline execution is complete.
Conclusion
This tutorial demonstrated how to configure a CodePipeline that triggers on changes in a CodeCommit repository and automatically deploys your application to AWS Elastic Beanstalk. With the added manual approval for production, you gain enhanced control over your deployments while automating routine tasks.
Happy deploying!
Watch Video
Watch video content
Practice Lab
Practice lab