‫Okay so next let's get into codePipeline.
‫So let's get started and we're going to create a Pipeline.
‫Okay, so CodePipeline is going to allow us
‫to link sources, builds and deploy stages
‫and we're going to create a very first simple Pipeline.
‫So Pipeline name let's enter a first name we'll call this
‫MyFirstPipeline sounds like a good name for it.
‫And right away we are greeted with creating a service role.
‫So this pipeline will do a lot of things,
‫it will talk to S3, it will talk to CodeCommit, it will talk
‫to Beanstalk and so as such we should be creating
‫a service role as an IAM role that will have the permissions
‫to do what it needs to do.
‫So something to remember CodePipeline requires
‫an IAM role attached to it.
‫Okay so we're going to click on New Service role
‫because we don't have any existing one
‫and here is a role name.
‫Now we can say allow CodePipeline to create a service role
‫so it can be used yet.
‫Advanced settings, we can choose a artifact store,
‫it could be an S3 bucket, a default one, it will leave
‫that option or we could specify a custom S3 bucket
‫if we wanted to.
‫We'll just leave everything as default because
‫it's simple enough this way.
‫Click on next, next we have to choose a source provider.
‫This is where the input artifacts are stored
‫for our Pipeline.
‫So guess what we have done CodeCommit just right now
‫so let's use CodeCommit.
‫But as you can see we could also integrates
‫with ECR, S3 or GitHub.
‫So let's use CodeCommits and we have to choose
‫a repository name before you have created the my-nodejs-app
‫so this is perfect and the branch name that we want to track
‫again which is the master branch.
‫Okay, now there are two ways for CodeCommit to be tracked,
‫there is the CloudWatch Events which is the recommended way
‫and a CloudWatch Event rule will be created automatically
‫such as whenever the CodeCommits repository
‫is updated automatically it will trigger a CodePipeline.
‫Alternatively you can use CodePipeline to check periodically
‫for changes but it won't be as fast
‫and it's not the recommended way.
‫As such we'll use CloudWatch Events and everything
‫will be created for us anyway.
‫Click on next, now we have Built and it's an optional step
‫and because right now we're not going to build anything
‫we cannot specify any Build but you could choose CodeBuild
‫or Jenkins and we'll obviously see CodeBuild later on
‫but for now I'm going to click on Skip build stage.
‫Okay let's skip it.
‫Now we can deploy.
‫And deploy provider can be many, many different things,
‫it could be all these things right here;
‫CloudFormation, CodeDeploy, Elastic Beanstalk,
‫Service Catalog, ECS, and S3.
‫So as you can see lots of choice but guess what
‫we've just learned Elastic Beanstalk,
‫so why not we use Beanstalk?
‫Okay and the application name is going
‫to be my-first-webapp-Beanstalk we've created
‫and the environment name is going to be my-Beanstalk-env
‫not the prod, we'll do prod later just the env.
‫Okay so what happens is that click on next
‫and we can review the entire CodePipeline we just created
‫so we created a CodePipeline, will have a ServiceRole name
‫it's going to pull all the code from CodeCommits
‫and it's going to not build anything
‫and deploy it to Beanstalk that sounds good.
‫Let's create this pipeline.
‫Okay, so the pipeline is going to be created.
‫And as soon as the pipeline will be created,
‫it will start doing its first action.
‫So as we can see now the source is already running it's blue
‫so it's about to run and then
‫it's going to deploy to Beanstalk.
‫So we have to be really quick and let's go
‫to Beanstock right now and we go to my-Beanstock-env
‫and as we can see right now
‫if we click on Beanstalk it's green.
‫Everything is green so this is the basics
‫that we've done from before.
‫But if we go to our CodeCommit repository
‫and have a look at the file index.html and we scroll down.
‫We see that the background color is blue.
‫So what should happen is that as soon as this pipeline
‫has first done its first run so it's running right now.
‫As soon as the deploy is done, we should be seeing
‫that our Beanstalk application is going to be updated
‫to a blue version.
‫So let's wait just a little bit
‫to see if that actually happens.
‫So the deploy has been successful and so if we go back
‫to the Beanstalk environment
‫and refresh this page, yep, it's blue.
‫So we've just done our first CodePipeline
‫where we hooked the CodeCommit repository
‫and the code went all the way through CodePipeline
‫into Elastic Beanstalk and updated our first environment
‫to something blue.
‫So congratulations, that's a really big first step
‫into the CICD world.
‫So under this stage what happened?
‫If we go back to our Beanstalk environment,
‫let me refresh this page
‫'cause there's no more work happen here okay.
‫It's running a new version and this version
‫is called CodePipeline and it has this entire ID.
‫So CodePipeline automatically created a new version for us
‫and we can also verify that by going one level up,
‫click on application versions and seeing that yes
‫this version was created with this description
‫and we can see the source of how it was created.
‫Okay, so now let's have a look at CodePipeline
‫and see if we can do even more fun stuff.
‫So why don't we extend the pipeline and for this
‫we'll click on edit and we'll scroll down,
‫so we have the source, we have the Deploy, where we Deploy
‫to our development Elastic Beanstalk environment.
‫But we're going to add a stage
‫and we'll call this one DeployToProd.
‫Now make sure not to have any spaces.
‫At stage and within this we can add an action group.
‫So you have to remember that's action groups
‫go within stages.
‫So the first one is going to be around
‫all the providers right here and it could be
‫a manual approval, it could be Beanstalk and so on.
‫So let's call this ManualApproval
‫and we're going to choose a manual approval.
‫Meaning okay, we are going to publish to prod only
‫once we get a manual approval.
‫For this you can also specify an SNS topic ARN
‫and its optional or URL for the review and comments,
‫we'll just click on done and we're done.
‫So here we can see that we can add another action group
‫as part of our stage.
‫So very important going into the exam,
‫sometimes they will ask you,
‫can action groups have multiple stages
‫or stages have multiple action groups,
‫well the answer is stages have multiple action group.
‫So the first action group here is a manual approval
‫and the second action group is going
‫to be DeployToProdBeanstalk
‫and the action provider is going to be Beanstalk.
‫Now the input artifacts is going
‫to be defined by the source.
‫The application name is the same as before
‫and the environment name is going to be prod this time.
‫Click on that, so now we can really look at what's happening
‫in this DeployToProd stage.
‫In this stage we have two action groups.
‫And the first one is a ManualApproval
‫and only then after the manual approval stage action group
‫is done then we will move on to the other action group
‫that deploy to prod Beanstalk.
‫So we can add sequentially action groups.
‫We can also add parallel actions
‫so we can have multiple things happening
‫on the right hand side and you can really be creative
‫so you can have sequential and parallel actions
‫within action groups and multiple action groups
‫within a stage.
‫Okay any enough times, so we can click on Done
‫and here we go, we have created our DeployToProd stage
‫now it hasn't run yet but this is good enough.
‫I'll go to the top and click on Save
‫and say save and here we go.
‫So now we can look at our pipeline, we have the source,
‫we have the Deploy and then we have DeployToProd
‫and it's waiting for a manual approval
‫and then this DeployToProd right here.
‫Okay, so how are we going to run this new pipeline?
‫Well, if you're following the source is CodeCommits.
‫So why don't we go in CodeCommits,
‫we'll go to our code index.html
‫and we're going to change it.
‫So let's edit this file straight from within the browser,
‫scroll down and click on background color red.
‫So we change from blue to red.
‫And all the way down we're going
‫to say the author name Stephane.
‫Stephane@example.com and the commit message is going
‫to be Changed index.html from blue to red.
‫Commit the changes and here we go.
‫So now we have changed our CodeCommits code
‫and so what we hope to happen is that
‫this code change will be propagated across
‫our entire CodePipeline and moved into dev
‫and then we'll be asked for a manual approval
‫and then deploy it into prod.
‫So let's go in dev right now just to make sure
‫that it's green.
‫So environments, well in dev and we are going
‫to look at the URL which is right here.
‫Currently it is blue so it hasn't been deployed yet
‫but let's go back to CodePipeline.
‫And as we can see, this has run just now
‫and now the deploy Beanstalk is happening
‫so that's wait a second.
‫And so dev has just succeeded so if we go back here
‫and refresh this page now yes we are red, excellent.
‫And let's go to DeployToProd and as we can see nothing
‫is happening because it is waiting for a approval.
‫So let's click on review and we say Changes look great!
‫Thank you and we're going to approve this change
‫and now that the manual approval has been approved,
‫what we should be seeing is that yes, DeployToProd
‫for Elastic Beanstalk is in progress.
‫So this is my prod environment.
‫So let's go to prod and currently it should be blue
‫but hopefully very soon it will turn red.
‫So let's go back to put CodePipeline and just wait a second.
‫And this is now succeeded, excellent.
‫So let's go back to this one refresh the page and here we go
‫we are red now, excellent.
‫And okay, so that's a pretty solid pipeline we here;
‫Source, DeployToDev and then DeplyToProd
‫that has a ManualApproval in it.
‫We can also look at the CodePipeline history
‫and we can see all the histories of our CodePipeline
‫for the execution and it could give
‫you some information around the details,
‫how long everything took, what was the status,
‫when thing started et cetera et cetera.
‫So that's it, that's a good first introduction
‫to CodePipeline as you can see it's a really powerful tool
‫and in the next lectures we'll be starting
‫to integrate CodeBuild in it to see how we can improve
‫this pipeline even further.
‫So hope you're excited,
‫I will see you in the next lecture.