AWS CodePipeline ties all the hard work you've completed so far together. A pipeline consists of stages, typically Source, Build, and Deploy. This is what triggers your newly created build and deployment projects automatically, at last - continuous delivery is on the horizon!
AWS CodePipeline Set Up
Navigate to the CodePipeline console.
Under Pipeline in the sidebar, click Getting started. Again, please take a few minutes to read the page and watch the video to understand better what CodePipeline is and how it's used. Click Create pipeline.
Give the pipeline a name. Later, this should be detailed regarding the pipeline's purpose - but for now you can name this one something simple like "DemoPipeline". Leave New service role selected, and a default role name will be generated for you. Click Next.
Source Stage
- Source provider - choose GitHub (Version 2)
- Connection - click Connect to GitHub, a new window will pop up.
- Give the connection a name, something like "PersonalGitHub"
- Click Install a new app
- Choose All repositories to allow AWS Connector to access all of your repositories, or Only select repositories, and select your demo deploy repo to limit its access (this can be changed later)
- Click Install
- Wait a moment, then click Connect
- Repository name - choose your demo deployment repo
- Branch name - choose main
- Start the pipeline on source code change - leave this checked. This way, any time the main branch is updated, the pipeline will launch
- Output artifact format - CodePipeline default will work for now
- Click Next
Build Stage
- Build provider - AWS CodeBuild
- Region - Match the region where your EC2 instance is located.
- Project name - The CodeBuild project you created previously
- Build type - Single build
- Click Next
Deploy Stage
- Deploy provider - AWS CodeDeploy
- Region - Match the region where your EC2 instance is located.
- Application name - The CodeDeploy application you created previously
- Deployment group - The deployment group you created previously
- Click Next
After reviewing your choices, click Create pipeline.
You'll be taken to the pipeline detail page, and execution will begin immediately.
You can watch live as the three stages are run:
- Source
- Build
- Deploy
This process will start automatically each time changes are pushed to the main branch of your project repository on GitHub. Great job! Your deployment is now completely automated - this is continuous delivery! In case you ever need to start the process manually, you can use the orange Release change button.
Build Source Ambiguity
At this point, the build stage requires some clarification. Since your previously-created build project and your new pipeline each authenticated with GitHub and were assigned a source repository - which is being used now?
To put it simply, when your build project is run by AWS CodePipeline, the pipeline source is used for the build. If you manually run a build from the CodeBuild console, the source designated within the build project is used. Take a look at your build project history.
If you try changing the build project source manually to CodePipeline, it is not an option.
Creating a build project that uses AWS CodePipeline exclusively as the source is possible. To accomplish this, a build project must be created simultaneously with the pipeline.
When creating a new pipeline, on the source selection page you can click the Create project button to create your build project right then.
A build project created in this way will display CodePipeline as its source.
Now, keep in mind that both offer identical functionality in regard to launching the build from within a pipeline. This information was provided simply for thoroughness, which might help you avoid a confusing situation down the road. You can leave your build project and pipeline alone, the way you originally created them is just fine.
Ok, now that you are automating deployment, it's time to fix up your project so that it actually runs. This will require passing your database credentials using another AWS tool.
Summary: AWS CodePipeline for Continuous Delivery
This lesson introduced AWS CodePipeline and helped you build your own pipeline that automates deployment. However, the application is still not running on the server due to missing database credentials. It's time to correct that in the next lesson!