In this tutorial, 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 tutorial is free tier eligible.

Manage Your AWS Resources

Sign in to the Console

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. Choose PHP from the drop-down menu and then click Launch Now.

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 web server 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.

continuous-delivery-pipeline-1

(click to zoom)

continuous-delivery-pipeline-1

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.

continuous-delivery-pipeline-1c

(click to zoom)

continuous-delivery-pipeline-1c

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:

 

  • GitHub

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

    continuous-delivery-pipeline-2a

    (click to zoom)

    continuous-delivery-pipeline-2a
  • 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.

    continuous-delivery-pipeline-2a1

    (click to zoom)

    continuous-delivery-pipeline-2a1

    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.
    continuous-delivery-pipeline-2b2

    (click to zoom)

    continuous-delivery-pipeline-2b2

    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 US Standard
    • Click Create.
    continuous-delivery-pipeline-2d

    (click to zoom)

    continuous-delivery-pipeline-2d

    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.
    continuous-delivery-pipeline-2g

    (click to zoom)

    continuous-delivery-pipeline-2g

    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.
    continuous-delivery-pipeline-2f

    (click to zoom)

    continuous-delivery-pipeline-2f
  • AWS CodeCommit

    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.

    continuous-delivery-pipeline-2a1

    (click to zoom)

    continuous-delivery-pipeline-2a1

    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.
    continuous-delivery-pipeline-2b2

    (click to zoom)

    continuous-delivery-pipeline-2b2

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

    continuous-delivery-pipeline-2b3

    (click to zoom)

    continuous-delivery-pipeline-2b3

    e. On the Create new repository page:

    • Repository name: enter PipelineRepo.
    • Select Create repository.
    continuous-delivery-pipeline-2c3

    (click to zoom)

    continuous-delivery-pipeline-2c3

    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.

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.


a. Click here to open the AWS CodePipeline console.

  • On the Welcome page, click Create pipeline
  • If this is your first time using AWS CodePipeline, an introductory page appears instead of Welcome. Click Get Started.
continuous-delivery-pipeline-3

(click to zoom)

continuous-delivery-pipeline-3

b. On the Step 1: Name page:

  • Pipeline name: enter the name for your pipeline, DemoPipeline. 
  • Click Next step.

Note: After you create a pipeline, you cannot change its name.

continuous-delivery-pipeline-3b

(click to zoom)

continuous-delivery-pipeline-3b

c. On the Step 2: Source page, select the location of the source you selected and follow the steps below:

  • GitHub

    Source Provider: GitHub

    • In the Connect to GitHub section, click Connect to GitHub.
    • A new browser window will open to connect you to GitHub. If prompted to sign in, provide your GitHub credentials. 
    • You will be asked to authorize application access to your account. Choose Authorize application.
    continuous-delivery-pipeline-3c

    (click to zoom)

    continuous-delivery-pipeline-3c

    Specify the repository and branch:

    • Repository: In the drop-down list, choose the GitHub repository you want to use as the source location for your pipeline. Click the forked repository in your GitHub account containing the sample code called aws-codepipeline-s3-aws-codedeploy_linux
    • Branch: In the drop-down list, choose the branch you want to use, master.
    • Click Next step.
    continuous-delivery-pipeline-3e

    (click to zoom)

    continuous-delivery-pipeline-3e
  • Amazon S3

    Source provider: Amazon S3.

    • Amazon S3 location: Type the name of the Amazon S3 bucket you created followed by the sample file you copied to that bucket (aws-codepipeline-s3-aws-codedeploy_linux.zip). For example, if you named your bucket awscodepipeline-demobucket-variable, then you would type: s3://awscodepipeline-demobucket-variable/aws-codepipeline-s3-aws-codedeploy_linux.zip.
    • Click Next step.
    continuous-delivery-pipeline-3c2

    (click to zoom)

    continuous-delivery-pipeline-3c2
  • AWS CodeCommit

    Source provider: AWS CodeCommit.

    • Repository name: Choose the name of your AWS CodeCommit repository. 
    • Branch name: Choose the name of the branch that contains the sample file.
    • Click Next step.
    continuous-delivery-pipeline-3c3

    (click to zoom)

    continuous-delivery-pipeline-3c3

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.

  • In Step 3: Build page, choose No Build.
  • Click Next step.

 

continuous-delivery-pipeline-3f

(click to zoom)

continuous-delivery-pipeline-3f

e. In the Step 4: Beta page:

  • Deployment provider: Click AWS Elastic Beanstalk. 
  • Application name: Click My First Elastic Beanstalk Application. 
  • Environment name: Click Default-Environment.
  • Click Next step.

Note: The name "Beta" is simply the name given by default to this stage of the pipeline, just as "Source" was the name given to the first stage of the pipeline.

continuous-delivery-pipeline-3g

(click to zoom)

continuous-delivery-pipeline-3g

f. In the Step 5: Service Role page:

  • Service Role: Click Create role.
  • You will be redirected to an IAM console page that describes the AWS-CodePipeline-Service role that will be created for you. Click Allow
  • After you create the role, you are returned to the Step 5: Service Role page where AWS-CodePipeline-Service appears in Role name. Click Next step.

Note: Service role creation is only required the first time you create a pipeline in AWS CodePipeline. If a service role has already been created, you will be able to choose it from the drop-down list of roles. Because the drop-down list will display all IAM service roles associated with your account, if you choose a name different from the default, be sure that the name is recognizable as the service role for AWS CodePipeline.

continuous-delivery-pipeline-3fa

(click to zoom)

continuous-delivery-pipeline-3fa

In this step, you will launch your pipeline. Once your pipeline has been created, it will start to run automatically. First, it detects the sample app code in your source location, bundles up the files, and then move them to the second stage that you defined. During this stage, it passes the code to Elastic Beanstalk, which contains the EC2 instance that will host your code. Elastic Beanstalk handles deploying the code to the EC2 instance.


a. In the Step 6: Review page, review the information and click Create pipeline.

continuous-delivery-pipeline-4

(click to zoom)

continuous-delivery-pipeline-4

b. 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.

continuous-delivery-pipeline-4a

(click to zoom)

continuous-delivery-pipeline-4a

c. In the status area for the Beta stage, click AWS Elastic Beanstalk

continuous-delivery-pipeline-4a2

(click to zoom)

continuous-delivery-pipeline-4a2

d. The AWS Elastic Beanstalk console opens with the details of the deployment.

  • Click the environment you created earlier, called Default-Environment
continuous-delivery-pipeline-4b

(click to zoom)

continuous-delivery-pipeline-4b

e. Click the URL that appears in the upper-right part of the page to view the sample website you deployed.

continuous-delivery-pipeline-6e

(click to zoom)

continuous-delivery-pipeline-6e

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.

  • GitHub

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

    • Open index.html
    • Select the Edit icon.
    continuous-delivery-pipeline-5b1

    (click to zoom)

    continuous-delivery-pipeline-5b1

    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!

    continuous-delivery-pipeline-5c

    (click to zoom)

    continuous-delivery-pipeline-5c

    c. Commit the change to your repository.

    continuous-delivery-pipeline-5c1

    (click to zoom)

    continuous-delivery-pipeline-5c1
  • Amazon S3

    a. On your desktop, visit the zip file you downloaded called aws-codepipeline-s3-aws-codedeploy_linux.zip.


    b. Edit the sample web app code:

    • Extract index.html from the zip file and open it using your preferred text editor. 
    • Update the header text that comes after “Congratulations!” so that it reads:

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

    • Copy the updated index.html file back into aws-codepipeline-s3-aws-codedeploy_linux.zip and replace the older version of index.html.
    continuous-delivery-pipeline-6b2

    (click to zoom)

    continuous-delivery-pipeline-6b2

    c. Reupload the edited file to your Amazon S3 bucket:

    • Return to the S3 bucket that you created earlier. 
    • Upload the updated aws-codepipeline-s3-aws-codedeploy_linux.zip file into the bucket. 

    Note: Because you enabled versioning when you first created the S3 bucket, S3 will save a copy of every version of your files.

    continuous-delivery-pipeline-6c2

    (click to zoom)

    continuous-delivery-pipeline-6c2
  • AWS CodeCommit

    a. Visit the zip file containing the sample code you downloaded called aws-codepipeline-s3-aws-codedeploy_linux.zip.


    b. Edit the sample web app code:
     
    • Extract index.html from the zip file and open it using your preferred text editor. 
    • Then update the header text that comes after “Congratulations!” so that it reads:

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

    continuous-delivery-pipeline-6b2

    (click to zoom)

    continuous-delivery-pipeline-6b2

    c. Commit and push the updated zip file to your CodeCommit 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.
continuous-delivery-pipeline-4a2

(click to zoom)

continuous-delivery-pipeline-4a2

e. The AWS Elastic Beanstalk console opens with the details of the deployment. Select the environment you created earlier, called Default-Environment.

continuous-delivery-pipeline-4b

(click to zoom)

continuous-delivery-pipeline-4b

f. Click the URL that appears in the upper-right part of the page to view the sample website again.  Your text has been updated automatically through the continuous deployment pipeline!

 

continuous-delivery-pipeline-6e

(click to zoom)

continuous-delivery-pipeline-6e

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.
continuous-delivery-pipeline-5d-6

(click to zoom)

continuous-delivery-pipeline-5d-6

b. Second, delete your Elastic Beanstalk application:

  • Visit the Elastic Beanstalk console. 
  • Click Actions.
  • Then click Terminate Environment.
continuous-delivery-pipeline-6

(click to zoom)

continuous-delivery-pipeline-6
  • Amazon S3

    c. If you created an S3 bucket for this tutorial, delete the bucket you created:

    • Visit the S3 console. 
    • Right-click the bucket name and select Delete Bucket
    • When a confirmation message appears, enter the bucket name and then click Delete.
    continuous-delivery-pipeline-6d

    (click to zoom)

    continuous-delivery-pipeline-6d
  • AWS CodeCommit

    c. If you created an AWS CodeCommit repository for this tutorial, visit the CodeCommit console and delete the repository that you created:

    continuous-delivery-pipeline-7a

    (click to zoom)

    continuous-delivery-pipeline-7a

    c. In the navigation pane, select Settings.

    • Click Delete Repository.
    • A confirmation window will pop up. Type the name of your repository and click Delete.
    continuous-delivery-pipeline-7b

    (click to zoom)

    continuous-delivery-pipeline-7b

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 practicing continuous deployment!

Now that you have learned to create a simple pipeline using AWS CodePipeline, you can learn more by visiting the following resources.

  • Create a more advanced, four-stage pipeline by following this guide. 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.
  • Quickly spin up a four-stage pipeline with a Jenkins build server by using our Pipeline Starter Kit.
  • Learn more about continuous delivery.
Yes
No