Set up a Continuous Deployment Pipeline in less than 15 min
Mohit Sharma

Set up a Continuous Deployment Pipeline in less than 15 min

In this article, you will learn how to create an automated software release pipeline that deploys a live sample app. You will create the pipeline using AWS CodePipeline, a service that builds, tests, and deploys your code every time there is a code change. You will use your GitHub account, an Amazon Simple Storage Service (S3) bucket, or an AWS CodeCommit repository as the source location for the sample app’s code. You will also use AWS Elastic Beanstalk as the deployment target for the sample app. Your completed pipeline will be able to detect changes made to the source repository containing the sample app and then automatically update your live sample app.

Continuous deployment allows you to deploy revisions to a production environment automatically without explicit approval from a developer, making the entire software release process automated.

Everything done in this article is free tier eligible.

Step1: Create a deployment environment

Your continuous deployment pipeline will need a target environment containing virtual servers, or Amazon EC2 instances, where it will deploy sample code. You will prepare this environment before creating the pipeline.


a. To simplify the process of setting up and configuring EC2 instances for this tutorial, you will spin up a sample environment using AWS Elastic Beanstalk. Elastic Beanstalk lets you easily host web applications without needing to launch, configure, or operate virtual servers on your own. It automatically provisions and operates the infrastructure (e.g. virtual servers, load balancers, etc.) and provides the application stack (e.g. OS, language and framework, web and application server, etc.) for you.

b. Name your web app and choose PHP from the drop-down menu(or any other language you are interested in) and then click Create Application.

No alt text provided for this image
No alt text provided for this image

Note: If you have created an Elastic Beanstalk application before, click: Create New Application on the upper-right corner. Name your application and create a new webserver environment. Select PHP as your platform and Single Instance as your environment type. If you are planning to remote login to your instances, select a key pair. Otherwise, leave default values for the remaining options and create the environment for your continuous deployment pipeline.

c. Elastic Beanstalk will begin creating a sample environment for you to deploy your application to. It will create an Amazon EC2 instance, a security group, an Auto Scaling group, an Amazon S3 bucket, Amazon CloudWatch alarms, and a domain name for your application.

Note: This will take several minutes to complete.

Step2: Get a copy of the sample code

In this step, you will retrieve a copy of the sample app’s code and choose a source to host the code. The pipeline takes code from the source and then performs actions on it.

You can use one of three options as your source: a GitHub repository, an Amazon S3 bucket, or an AWS CodeCommit repository. Select your preference and follow the steps below:

No alt text provided for this image
No alt text provided for this image

* Above, I am using GitHub but you are free to use any of the three options given below.

a. If you would like to use your GitHub account:

  • Visit our GitHub repository containing the sample code at https://github.com/imoisharma/aws-codepipeline-s3-codedeploy-linux-2.0 
  • Fork a copy of the repository to your own GitHub account by clicking the Fork button in the upper-right corner.
Amazon S3

a. If you plan to use Amazon S3 as your source, you will retrieve the sample code from the AWS GitHub repository, save it to your computer, and upload it to an Amazon S3 bucket.

  • Visit our GitHub repository containing the sample code at https://github.com/imoisharma/aws-codepipeline-s3-codedeploy-linux-2.0
  • Click the dist folder.

b. Save the source files to your computer:

  • Click the file named aws-codepipeline-s3-aws-codedeploy_linux.zip 
  • Click View Raw.
  • Save the sample file to your local computer.

c. Click here to open the Amazon S3 console and create your Amazon S3 bucket:

  • Click Create Bucket
  • Bucket Name: type a unique name for your bucket, such as awscodepipeline-demobucket-variables. All bucket names in Amazon S3 must be unique, so use one of your own, not one with the name shown in the example.
  • Region: In the drop-down, select the region where you will create your pipeline, such as North-Virginia. 
  • Click Create.

d. The console displays the newly created bucket, which is empty.

  • Click Properties.
  • Expand Versioning and select Enable Versioning. When versioning is enabled, Amazon S3 saves every version of every object in the bucket.

e. You will now upload the sample code to the Amazon S3 bucket: 

  • Click Upload.
  • Follow the on-screen directions to upload the .zip file containing the sample code you downloaded from GitHub.
AWS Code Commit

a. If you plan to use AWS CodeCommit as your source, you will retrieve the sample code from the AWS GitHub repository, save it to your computer, and upload it to an AWS CodeCommit repository.

  • Visit our GitHub repository containing the sample code at https://github.com/imoisharma/aws-codepipeline-s3-codedeploy-linux-2.0
  • Select the dist folder.

b. Save the source files to your computer:

  • Select the file named aws-codepipeline-s3-aws-codedeploy_linux.zip. 
  • Select View Raw.
  • Save the sample file to your local computer.

d. Click here to open the AWS CodeCommit console and select Get Started.


e. On the Create new repository page:

  • Repository name: enter PipelineRepo.
  • Select Create repository.

f. Connect to your repository and then push a copy of the sample file to it. For instructions, see Connect to an AWS CodeCommit Repository.

Step3: Create your Pipeline

In this step, you will create and configure a simple pipeline with two actions: source and deploy. You will provide CodePipeline with the locations of your source repository and deployment environment.


d. A true continuous deployment pipeline requires a build stage, where code is compiled and unit tested. CodePipeline lets you plug your preferred build provider into your pipeline. However, in this tutorial, you will skip the build stage.

No alt text provided for this image
No alt text provided for this image
  • In Step 3: Build page, choose No Build.
  • Click Next step
No alt text provided for this image

e. In Step 4: Deploy Stage:

  • Deployment provider: Click AWS Elastic Beanstalk. 
  • Application name: MYEBS. 
  • Environment name: Click Myebs-env.
  • Click Next step.
No alt text provided for this image

Click next and review your information and click create pipeline

No alt text provided for this image
After your pipeline is created, the pipeline status page appears and the pipeline automatically starts to run. You can view progress as well as success and failure messages as the pipeline performs each action.  To verify your pipeline ran successfully, monitor the progress of the pipeline as it moves through each stage. The status of each stage will change from No executions yet to In Progress, and then to either Succeeded or Failed. The pipeline should complete the first run within a few minutes.

After your pipeline is created, the pipeline status page appears and the pipeline automatically starts to run. You can view progress as well as success and failure messages as the pipeline perform each action. To verify your pipeline ran successfully, monitor the progress of the pipeline as it moves through each stage. The status of each stage will change from No executions yet to In Progress, and then to either Succeeded or Failed. The pipeline should complete the first run within a few minutes.

Now go to your EBS environment and click on the URL to view the sample website you deployed.

No alt text provided for this image

You have successfully created an automated software release pipeline using AWS CodePipeline! Using CodePipeline, you created a pipeline that uses GitHub, Amazon S3, or AWS CodeCommit as the source location for application code and then deploys the code to an Amazon EC2 instance managed by AWS Elastic Beanstalk.

No alt text provided for this image

Step 5: Commit a change and then update your app

In this step, you will revise the sample code and commit the change to your repository. CodePipeline will detect your updated sample code and then automatically initiate deploying it to your EC2 instance via Elastic Beanstalk. 

Note that the sample web page you deployed refers to AWS CodeDeploy, a service that automates code deployments. In CodePipeline, CodeDeploy is an alternative to using Elastic Beanstalk for deployment actions. Let’s update the sample code so that it correctly states that you deployed the sample using Elastic Beanstalk.

a. Visit your own copy of the repository that you forked in GitHub.

  • Open index.html
  • Select the Edit icon

b. Update the webpage by copying and pasting the following text on line 30: 

You have successfully created a pipeline that retrieved this source application from GitHub and deployed it to one Amazon EC2 instance using AWS Elastic Beanstalk. You’re one step closer to practicing continuous deployment!

c. Commit the change to your repository.

d. Return to your pipeline in the CodePipeline console. In a few minutes, you should see the Source change to blue, indicating that the pipeline has detected the changes you made to your source repository. Once this occurs, it will automatically move the updated code to Elastic Beanstalk.

  • After the pipeline status displays Succeeded, in the status area for the Beta stage, click AWS Elastic Beanstalk.

e. The AWS Elastic Beanstalk console opens with the details of the deployment. Select the environment you created earlier. And click the URL again from EBS environment again.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Step 6: Clean up your resources

To avoid future charges, you will delete all the resources you launched throughout this tutorial, which includes the pipeline, the Elastic Beanstalk application, and the source you set up to host the code. 

a. First, you will delete your pipeline:

  • In the pipeline view, click Edit. 
  • Click Delete.
  • Type in the name of your pipeline and click Delete.

(see above)

b. Second, delete your Elastic Beanstalk application:

  • Visit the Elastic Beanstalk console. 
  • Click Actions.
  • Then click Terminate Environment.
No alt text provided for this image
No alt text provided for this image


In future, I'll show you how to create a more advanced, four-stage pipeline. This pipeline uses a GitHub repository for your source, a Jenkins build server to build and test the project, and an AWS CodeDeploy application to deploy the built code to a staging server.

Congratulations!

You have successfully created an automated software release pipeline using AWS CodePipeline! Using CodePipeline, you created a pipeline that uses GitHub, Amazon S3, or AWS CodeCommit as the source location for application code and then deploys the code to an Amazon EC2 instance managed by AWS Elastic Beanstalk. Your pipeline will automatically deploy your code every time there is a code change. You are one step closer to practising continuous deployment!

If you have further question don't hesitate to mail me or seeking a Contributor who makes things happen contact at [email protected] 

要查看或添加评论,请登录

??Mohit Sharma的更多文章

  • Change the data type of columns in Pandas

    Change the data type of columns in Pandas

    You have three main options for converting types in pandas: to_numeric() - provides functionality to safely convert…

    14 条评论
  • Text Parsing in Python with US-Patent Data

    Text Parsing in Python with US-Patent Data

    In today’s world there is simply much more unstructured data than structured data. Unstructured data(for instance —…

  • Time Zone

    Time Zone

    Take a deep breath THINK! New York is three hours ahead of California, but that does not make California slow Cameroon…

  • Lifecycle of Data Science Projects

    Lifecycle of Data Science Projects

    Lifecycle of data science projects is just an enhancement to the CRISP-DM workflow process with some alterations- Data…

    3 条评论
  • Deep Learning Resources

    Deep Learning Resources

    Getting the right resources at right time not only focused us on our goals but also makes our self one step forward…

  • Cheat Sheets for AI, Neural Networks, Machine Learning, Deep Learning & Big Data

    Cheat Sheets for AI, Neural Networks, Machine Learning, Deep Learning & Big Data

    The Most Complete List of Best AI Cheat Sheets Resources Big-O Algorithm Cheat Sheet: https://bigocheatsheet.com/ Bokeh…

  • Free Resources for Data Science

    Free Resources for Data Science

    Demand for skilled data scientists continues to be sky-high, with IBM recently predicting that there will be a 28%…

  • Journey!

    Journey!

    The results you get are a reflection of the actions you take. Just like any mathematical formula, all outputs in life…

社区洞察

其他会员也浏览了