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.
How does Code Pipeline work?
The below diagram from the AWS documentation shows the structure of a 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.
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.
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.
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
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
Step 3) Next you need to provide a source provider. We can choose Github for our example.
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.
Step 5) Next you have to choose the repository and the branch from Github from where the code needs to be downloaded.
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.
Step 7) Next you need to choose a deployment provider. Here we can choose AWS Code Deploy as an example.
You can choose the relevant Code Deployment configuration
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.
Step 9) Once the Role is created, choose the Role and click on the next step
Step 10) Finally you can do a review and create your pipeline
Step 11) Immediately a deployment will kick off. So the first stage will start downloading the files from Github.
Step 12) Once the deployment is complete, you will get be able to see the progress of the Pipeline.
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.
If you want you can force a change by clicking on the Release Change button.
The Edit button allows you to edit the Pipeline.
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.
Preparing for AWS Certification? Pass in First Attempt with Whizlabs AWS Certification Training Courses!