Blog Amazon Web Services Working with Code Pipeline
code pipeline

Working with Code Pipeline

Exam Objective

The topic “Working with Code Pipeline” addresses the Continuous Delivery and Process Automation topic as highlighted in the AWS Blueprint for the exam guide.

Check out the AWS Certified DevOps Engineer Professional Free and Practice Tests here.

The AWS Code Pipeline services allow one to build a continuous integration and continuous delivery pipeline. This is an important service especially for those organizations that are looking towards implementing DevOps in their organizations. The AWS Code Pipeline service also has built-in integration with popular continuous integration tools such as Jenkins. The Code Pipeline tool can be used to pull out code from famous source code configuration management tools such as Git.

[divider /]

How does Code Pipeline work?

The below diagram from the AWS documentation shows the structure of a pipeline.

Pipeline

1) Stages – The pipeline consists of multiple stages. In your organization, you can have multiple stages such as staging and production.

2) Action – Each stage consists of a series of actions which specify what must be done on the artifact. Each stage can only perform one revision of the source code at a time. All of the artifacts are stored in an S3 bucket. For example, the code which needs to be built will be copied to the S3 bucket for the pipeline. This becomes the input artifact.

3) Transition – A transition is an action which is performed when one stage is moved to the next in the pipeline. An approval action can also put in place so that if a manual approval is required before it goes to the next stage.

[divider /]

Black Friday Sale

[divider /]

The below diagram from the AWS documentation shows an example of a pipeline. In the below diagram we have

1) Source Stage – This is where the code is going to come from. In this diagram, it shows that the code is coming from CodeCommit. The code can also come from Git.

2) Build Stage – In this stage, the code can be built into a binary.

3) Integration Stage – There is a separate stage that performs an Integration test.

4) Production Stage – This stage moves the code to production. Here the code is being deployed using the CodeDeploy AWS service.

Example Pipeline

Getting started with Code Pipeline

Now let’s look at how we can start working with CodePipeline. The following example will create 2 stages, one which downloads the code from a Github repository. And the next stage is used to deploy the code using the AWS CodeDeploy service. Please refer to the article on CodeDeploy on how to create a Code Deploy service.

Since we are using a code deploy service, we have to ensure that we have the appspec.yml file in our Github repository as shown below.

You can use any public GitHub repository. The below snapshot shows a github repository which has the appspec.yml file and a sample HTML file which will be get deployed to the EC2 Instances.

Getting Started

So let’s now perform the following steps to get the Code Pipeline structure in place

Step 1) Go to Developer Tools and choose CodePipeline

Code Pipeline

Then choose to create a new Pipeline

Step 2) Give a name for the pipeline. In the below example, we are giving a name of DemoPipeline. Then click on the Next step

AWS Code Pipeline

Step 3) Next you need to provide a source provider. We can choose Github for our example.

Source Provider

Step 4) Next you will be requested to connect to Github. Here you can also mention running the pipeline when any changes to the source content are detected.

Pipeline Execution

Step 5) Next you have to choose the repository and the branch from Github from where the code needs to be downloaded.

GitHub

Step 6) Next you need to choose if you need to have a build server in place. For the current demo, let’s leave it as no Build.

Create Pipeline

Step 7) Next you need to choose a deployment provider. Here we can choose AWS Code Deploy as an example.

Deployment Provider

                  You can choose the relevant Code Deployment configuration

AWS Code Deploy

Step 8) Finally you can create a role. This will allow CodePipeline to create work with the resources in your AWS account. You can click on Create role to create a new role.

Create Pipeline

Step 9) Once the Role is created, choose the Role and click on the next step

AWS

Step 10) Finally you can do a review and create your pipeline

Pipeline Settings

Step 11) Immediately a deployment will kick off. So the first stage will start downloading the files from Github.

GitHub

Step 12) Once the deployment is complete, you will get be able to see the progress of the Pipeline.

GitHub

Step 13) Whenever you make a change to the Github repository, the pipeline will again be triggered. Here it will download the latest code from the mentioned branch.

code pipeline

If you want you can force a change by clicking on the Release Change button.

The Edit button allows you to edit the Pipeline.

[divider /]

Additional Points to Remember

1) The AWS Code Pipeline services allows one to build a continuous integration and continuous delivery pipeline

2) The Code Pipeline consists of the following parts

  • Stages – In your organization, you can have multiple stages such as staging and production.
  • Action – Each stage consists of a series of actions which specify what must be done on the artifact
  • Transition – A transition is an action which is performed when one stage is moved to the next in the pipeline

3) Whenever a change is made to the source code configuration repository, the code pipeline flow is triggered.

[divider /]

Preparing for AWS Certification? Pass in First Attempt with Whizlabs AWS Certification Training Courses!

About Mark Oswald

Mark is an experienced software engineer and technology blogger. He has over five years of experience in writing in different technological domains. Writing is his passion and he contributes regularly to the Whizlabs blog to share his knowledge.
Spread the love

LEAVE A REPLY

Please enter your comment!
Please enter your name here