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:
Set up a GitHub repository for the application
codeCreate an AWS Elastic Beanstalk environment
to deploy the applicationConfigure AWS CodeBuild to build the source
code from GitHubUse AWS CodePipeline to set up the continuous
delivery pipeline with source, build, and deploy
stages
Visual representation of End Architecture:
Task 1: Set Up Git Repo
Step 1: Fork a GitHub repository to create a new one
- navigate to GitHub
- open the aws-elastic-beanstalk-express-js-sample repo
- Choose the white Fork button on the top right corner of the screen and choose Create a fork
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
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
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
- under the heading Application name, enter DevOpsGettingStarted
- Select Node.js from the Platform dropdown menu.
- Ensure that sample application is selected.
- 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.
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.
- In the Project name field, enter Build-DevOpsGettingStarted.
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
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.
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: - '**/*'
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
- 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
In the Pipeline name field, enter Pipeline-DevOpsGettingStarted.
Confirm that New service role is selected.
Choose the Next button.
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.
- Select main from the branch dropdown menu.
- Confirm that GitHub webhooks is selected.
- Choose the Next button.
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.
- 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 DevOpsGettingStartedSelect DevOpsGettingStarted-env from the
Environment name textbox.Choose the Next button.
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.
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
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.
- In the Stage name field, enter Review.
- Choose the Add stage button.
- In the Review stage, choose the 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 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)