1. Home
  2. Training Library
  3. Amazon Web Services
  4. Courses
  5. Certified Developer for AWS- Deployment and Security

Amazon CodePipeLine

Start course
1h 59m

In this course we learn to

Recognize and implement secure procedures for optimum cloud deployment and maintenance.
Demonstrate ability to implement the right architecture for development, testing, and staging environments. 

Shared Security model
Compliance and best practices
Identity and Access Management (IAM)
Protecting data at Rest / In Transit
Identity Federation
Threat Mitigation
Amazon CloudFront Security

Deployment Services

Demonstrate ability to implement the right architecture for development, testing, and staging environments.
Understand the core AWS services, uses, and basic architecture best practices
Amazon CodeDeploy
Amazon CodePipeLine
Amazon CodeCommit

If you have thoughts or suggestions for this course, please contact Cloud Academy at support@cloudacademy.com.


Hi. Welcome to our last lecture, and in this lecture we will explore CodePipeline, and we will also explore how to integrate CodePipeline with CodeDeployCodeDeploy.

CodePipeline is a continuous delivery service. You can integrate CodePipeline with many tools out there, for example GitHub or Jenkins.

So, how it works. You have to define a source for your application. With CodePipeline you can create a pipeline, and you can define the steps to deploy your software. The first step would be Build. If you are using a language like Java, that you have to compile files to generate bi-code, you could do it in this phase. Then you can have a Staging phase, meaning that you will deploy your application in a development environment, launch a few tests upon it, and once it's done you could ship it to Production.

Since software is something that's continuously changing, you could Change your software and start the whole process again. Every time you push a new vision of your software through the source, it will start the whole process again.

About the pricing, it costs one dollar per active pipeline per month. Let's now go to the AWS console, and see how it works.

We will view everything from scratch in here, so let's first define a place to start our source. I will start on S3. I will create a new bucket, and I will call it "app-great-scott," and click on create. To use our bucket as our source in CodePipeline, we need to enable Versioning. Okay, it's done.

Let's now launch a few instances. As I did in the CodeDeploy lecture, I'll use a cloud formation template, to deploy a few instances for us. The template is available in this page, and since I'm using the Oregon region, that's the template that I want to use. I'll call it "dev." Insert my key. And here I will tag it, "env dev". And here we are creating the instance to launch a new CodeDeploy application. And here we are defining the tags that we're using in our deployment group. Click on Next.. Next again. And we can create. So, now let's do the same process again, this time for the "Prod" instances. Let's wait 'till it finishes, and we can move forward. Okay, it's done.

Let's now go to CodeDeploy. I will create a new application here, but this time I will choose custom deployment. Application name will be great-scott, I'll create the dev deployment group. And, my environment will be Dev. Since it's a dev deployment group, I will choose all at once, and I have to select the service role. Okay, our application was created, and notice that we didn't have to define any source location.

Let's now create our Prod deployment group. Since it's a Prod, I'll choose deploy one at a time. It will not make a big difference in our example, but in a production environment that makes sense. Okay, now we have two deployment groups. Now we have to upload our source code to our bucket. I will do this by using the AWS command line interface. I have in here this sample app folder. This is the folder that we use to deploy a sample application in CodeDeploy. We can see that in here we have the appspec file and the index file, and a few scripts. So, let's zip this folder and upload it to S3. We have our zip file, now let's move it to S3. The file was moved, and let's check the results in here. We have a bundle file, and we need this address in order to move forward. Let's now got to the CodePipeline console.

So, finally let's get started with CodePipeline. We have to create a pipeline name, so we'll call it "pipe-great-cott". Now we have to define our source provider, in our case it would be Amazon S3. Here we could define a build step, I will not deal with it right now, I will just click on next step. No build, sorry. And deployment provider, we will deploy our application on CodeDeploy. We have to define our application name, and we have to define a deployment group.

Let's start with only the dev deployment group. And here we have to create a role, in my case I already have a role, but if you don't have it you can click in here and create a new role. Next, we can review our pipeline and create pipeline. Okay, our pipeline was created, and now we can watch it running. CodePipeline has recognized our source, and now it's starting the deployment on our dev environment. All right, our deployment was completed. Let's now check the results. We can see this simple application.

Let's start really messing around with our pipeline. I will click on edit, and in here you can see that our source is Amazon S3. And it's sending an output, we call it artifact. And the output is MyApp. Here, we are deploying using CodeDeploy, this is our application name, our deployment group, and in here we can define an input. And notice that is the output from our source, so we are inserting the files from our source files to be deployed in our deployment group.

Now let's add a new stage. We'll call it "Deploy-Prod". Define an action, and we want to deploy. I'll call it "Prod". We will deploy it in CodeDeploy, great-scott app. This time the deployment group Prod. And we have to define our input, in this case MyApp. Save pipeline.

Okay, now, we can release a new change. We could do this by uploading a new bundle file to our S3 bucket, or we can click in here, and it will release the latest version of our software. Notice that, again, it will evaluate the source, it will deploy on dev and then deploy on Prod. So, let's wait 'till it finishes. Awesome. Our application was deployed on the Prod environment, let's check it out. You can see it's the same application as the dev environment.

But, now let's make things real interesting. Let's add Jenkins in this work folder. I'll launch a new instance to serve as our Jenkins server. Click on launch. I'll select Red Hat, t2.micro is okay. We have to create a new role for our Jenkins instance. So let's do this. Create a new role. It should be an EC2 role. And this is the managed policy that we have to select. Okay, now we have our role. We can click on refresh, select Jenkins, and on advanced we need to insert some user data. I'll create a new security group, and we have to also open our 8080 port. I'll wait 'till it launches, and then I will get back.

All right, it's ready. And we have our Jenkins server up and running. We have to configure the CodePipeline plugin first, so let's do this. Manage Jenkins, manage plugins. Here on available you can type CodePipeline. Okay, click on restart. Let's check if it's really installed. And, it's here. Back on Jenkins, let's create a new item. I will call it "great-scott-dev". And it's a freestyle project. We need to select execute concurrent builds if necessary. Our source is CodePipeline. You have to select the right region, and we are going to do a build. And our provider will be Jenkins, not Jenkins, let's type in "great-scott-dev". All right, five stars in here, meaning that we will do it every minute. We want to do something in our build process. Right now, I'll just do an echo comment, and we need to send something to CodePipeline. Just select, CodePipeline publisher, click on add, and leave it blank. Let's hit save.

Let's get back to our pipeline and configure it. Click on edit. I will add a new stage right here after the source, and "Build-dev". I will add an action, this time build, and an action name. Build provider, we will want to add a new one. The provider name must be the same that we've defined in here. So, I will just copy and paste it. We have to specify the URL of our server and a project name. In our case our project name is "great-scott-dev". Okay let's save. Click edit, and add this step again.

We have to select in here our input, in this case it will be MyApp, and we have to define an output because Jenkins we will build our source, and it will spit out something. So, we'll call "output-dev". Here, on the dev stage, we have to change our input. So, let's test only Jenkins this time. We can stop a workflow by clicking here, we just have to specify a reason. In this case it's test. And disable. Let's ask for a new release change.

Okay, success, let's check it out on Jenkins. We can go back to the dashboard, select our project, and we can see in here that we have a log file. Jenkins has received successfully the file from CodePipeline, we did an echo build comment in here, and it worked. It has sent the output to CodePipeline, and this is our result. Okay, it's working, but that's not really what I want you to do with Jenkins. This is the new Great_Scott app. It's basically the sample app, but I've added a couple of things in here. First, I've added this sed instance ID, which will grab the instance ID from the instance that is running our environment, and it will replace something in our index.html file. I have changed the index.html file, and I have changed the appspec file.

Let's release a new change. Here I am at the Great_Scott folder. And in here I will do the same thing that I did a few minutes ago, I will upload our bundle file to S3. Let's get back to the CodePipeline console and see it running our new release change. Let's check the results. Okay, you can see our instance ID here, we are changing it during the CodeDeploy deployment. And, we also can see a deployment group in here, that's not quite what I would like to see in here. Let me just refresh the other deployment group. And just by seeing this page, I can't tell which one is dev and which one is Prod, and I would like to see this information in here. So let's change a little bit our workflow, and also change how Jenkins builds our application.

I will start here in Jenkins. The great-scott-dev, I will change the build. I will do it by inserting this comment. Hit save. And I will also create a new item, this time "great-scott-prod". Again, a freestyle project. It will be "great-scott-prod". And since it's prod, I will just change it in here. Configure our output and hit save.

Okay, we are almost ready. We also have to insert a new step in our workflow. After we deploy to Prod I will add a new stage. I will call it "Build-prod". I will select our input as MyApp, and it will output our prod version. Okay, now we are ready to save, and, I'll ask for a new release change.

Okay, we can see a bunch of green results, and now let's check how it looks on the web pages. Let me refresh this first one, and we can see that it's the development environment. Great. And here, refresh, production, it's working as expected. So in this lecture we learned how to deploy an application from scratch using CodePipeline and CodeDeploy. I hope you enjoyed this course, and feel free to leave us a comment below.



About the Author
Andrew Larkin
Head of Content
Learning Paths

Andrew is fanatical about helping business teams gain the maximum ROI possible from adopting, using, and optimizing Public Cloud Services. Having built  70+ Cloud Academy courses, Andrew has helped over 50,000 students master cloud computing by sharing the skills and experiences he gained during 20+  years leading digital teams in code and consulting. Before joining Cloud Academy, Andrew worked for AWS and for AWS technology partners Ooyala and Adobe.