1.2 - PaulDuvall/aws-compliance-workshop GitHub Wiki
1.2 AWS CodePipeline
Review and ensure that you have setup your development environment before going through the steps below. Use the S3 bucket you created when setting up your development environment.
In CodePipeline, stages are composed of a collection of actions. Actions perform the work in a pipeline. Within actions, you will see integrations with other tools, running commands to build, test, deploy, and release your service. Currently, there are six action types: Source, Build, Test, Deploy, Invoke, and Approval. In this course, you will be using four types: Source, Build, Test, and Deploy. You can run actions in parallel. A stage is not complete until all actions are successful.
You can enable and disable transitions to acts as gates between stages and several other features. You will be learning more about this and other features of CodePipeline in other lessons.
In the figure below, you see a simple pipeline in CodePipeline that illustrates stages, actions, a transition, revisions, and action provider types.
With CodePipeline, you can do the following:
- "Automate your release processes - AWS CodePipeline fully automates your release process from end to end, starting from your source repository through build, test, and deployment. You can prevent changes from moving through a pipeline by including a manual approval action in any stage except a Source stage. You can automatically release when you want, in the way you want, on the systems of your choice, across one instance or multiple instances.
- Establish a consistent release process - Define a consistent set of steps for every code change. AWS CodePipeline runs each stage of your release according to your criteria.
- Speed up delivery while improving quality - You can automate your release process to allow your developers to test and release code incrementally and speed up the release of new features to your customers.
- Use your favorite tools - You can incorporate your existing source, build, and deployment tools into your pipeline. For a full list of AWS services and third-party tools currently supported by AWS CodePipeline, see Product and Service Integrations.
- View progress at-a-glance - You can review real-time status of your pipelines, check the details of any alerts, retry failed actions, view details about the source revisions used in the latest pipeline execution in each stage, and manually rerun any pipeline." (Source)
Stages
"Each stage has a unique name within a pipeline, and contains a sequence of actions as part of its workflow. A stage can only process one revision at a time. A revision must run through a stage before the next revision can run through it. All actions configured for a stage must be completed successfully before the stage is considered complete. After a stage is complete, the pipeline will automatically transition the revision and its artifacts created by the actions in that stage to the next stage in the pipeline" Source
While there are many different types of limits in CodePipeline, here are some of the key limits:
- Number of stages in a pipeline - Minimum of 2, maximum of 10
- Number of actions in a stage - Minimum of 1, maximum of 50
- Maximum number of parallel actions in a stage - Maximum of 50
- Maximum number of sequential actions in a stage - Maximum of 50
For more information see Limits in AWS CodePipeline and Action Structure Requirements in AWS CodePipeline.
Actions
"Every stage contains at least one action, which is some kind of task performed on the artifact in that stage. Pipeline actions occur in a specified order, in sequence or in parallel, as determined in the configuration of the stage." Source
Action Type | Support Providers |
---|---|
Source | Amazon S3, AWS CodeCommit, GitHub, ECR |
Build | AWS CodeBuild, Third-Party Providers |
Test | AWS CodeBuild, Third-Party Providers |
Deploy | AWS CodeDeploy, AWS CloudFormation, Amazon ECS, AWS Elastic Beanstalk, AWS OpsWorks, Third-Party Providers |
Invoke | AWS Lambda |
Approval | Manual |
"If your release process includes activities that are not included in the default actions, such as an internally developed build process or a test suite, you can create a custom action for that purpose and include it in your pipeline." Source
Artifacts
Each action can declare input and output artifacts that will be stored in an S3 bucket. These are objects that it will either expect to have before it runs, or objects that it will produce and make available after it runs.
For example, an Output artifact of a Source stage is the contents of the entire source repository that is stored in a zip file in an S3 bucket. This Output artifact is then used by subsquent downstream stages to build and test the software. Likewise, the output of a Build stage might be the code that is built and packaged into a deployable artifact that can be used to deploy to environments.
In the figure below, you see how Input and Output artifacts are defined in CodePipeline stages.
For more information, see Troubleshooting AWS CodePipeline Artifacts.
Revision
"A revision is a change made to a source that is configured in a source action for AWS CodePipeline, such as a pushed commit to a GitHub repository or an update to a file in a versioned Amazon S3 bucket." Source
CodePipeline Benefits
Rapid delivery
"AWS CodePipeline automates your software release process, allowing you to rapidly release new features to your users. With CodePipeline, you can quickly iterate on feedback and get new features to your users faster." Source
"Automating your build, test, and release process allows you to quickly and easily test each code change and catch bugs while they are small and simple to fix. You can ensure the quality of your application or infrastructure code by running each change through your staging and release process." Source
Configurable workflow
"AWS CodePipeline allows you to model the different stages of your software release process using the console interface, the AWS CLI, AWS CloudFormation, or the AWS SDKs. You can easily specify the tests to run and customize the steps to deploy your application and its dependencies." Source
Get started fast
"With AWS CodePipeline, you can immediately begin to model your software release process. There are no servers to provision or set up. CodePipeline is a fully managed continuous delivery service that connects to your existing tools and systems." Source
Easy to integrate
"AWS CodePipeline can easily be extended to adapt to your specific needs. You can use our pre-built plugins or your own custom plugins in any step of your release process. For example, you can pull your source code from GitHub, use your on-premises Jenkins build server, run load tests using a third-party service, or pass on deployment information to your custom operations dashboard." Source
CodePipeline and this Course
In this course, you will be using CodePipeline to create a continuous delivery workflow for compliance. As you define compliance as code, you version, build, test, and deploy this code to your AWS accounts using CodePipeline.
Clone the CodeCommit Repository
- If you haven't done so already, create a CodeCommit repo
- Clone the CodeCommit repo.
cd ~/environment/ccoa
git clone https://git-codecommit.us-east-1.amazonaws.com/v1/repos/ccoa-codecommit
- Change the directory to your local CodeCommit repo:
cd ~/environment/ccoa/ccoa-codecommit
touch README.md
- Open the README.md file and paste the template configuration below and save.
# 1.2 README
- Add and commit files to your CodeCommit repo
git add .
git commit -am "initial commit of lesson1 files"
git push
Create a deployment pipeline using AWS CodePipeline
- Go to the CodePipeline console
- Click Create pipeline
- Enter a Pipeline name (e.g.
ccoa-1-pipeline-console
) - Keep the Allow AWS CodePipeline to create a service role so it can be used with this new pipeline checkbox selected
- Click Next
- Choose CodeCommit as the Source provider
- Choose ccoa-codecommit as the Repository name (based on Create AWS CodeCommit repository )
- Choose master as the Branch name
- Under Change detection options, leave Amazon CloudWatch Events (recommended) selected
- Click Next
- Click Skip build stage
- Choose Amazon S3
- Enter a BucketName based on the S3 bucket you created previously in this lesson (e.g.
ccoa-ACCOUNTID
) - Choose an ObjectKey (e.g.
my-deployment.zip
)
Modify the Pipeline
- Select the pipeline you just created
- Click the Edit button to edit the pipeline
- Click the Edit stage button to view how to edit a stage
- Click the Add stage button
- Click the Add action button
- Edit an existing action by clicking on the Pencil icon on the action
- Click the Disable transition button
- Click the Enable transition button
- Click on a Revision link
- Click the View current revisions button
- Click the View history button
- Click the Release change button
- Release Change
Transitions
To disable a transition, follow the instructions below.
aws codepipeline disable-stage-transition --pipeline-name ccoa-1-pipeline-console --stage-name Deploy --transition-type Inbound --reason "My Reason"
To enable a transition, follow the instructions below.
aws codepipeline enable-stage-transition --pipeline-name ccoa-1-pipeline-console --stage-name Deploy --transition-type Inbound
Export a Pipeline
After manually creating a pipeline, you can export its contents in JSON format using the CLI. This is helpful when you want to run it from the CLI later or through AWS CloudFormation.
To pipe the contents of a specific pipeline to a JSON file, run the command below as found in your AWS CodePipeline Console.
aws codepipeline get-pipeline --name ccoa-1-pipeline-console > my-pipeline.json
For more information, see get-pipeline.
Delete a Pipeline
To delete a pipeline, follow the instructions below.
From the AWS CodePipeline console, select the pipeline you previously created:
- Select Edit
- Select Delete
- Type in the name of the pipeline to confirm deletion and select Delete
Additional Resources
- For more information, see: Create a Pipeline using the AWS CodePipeline Console.
- Tutorial: Create a Pipeline That Uses Amazon S3 as a Deployment Provider .
Cleanup
Go to Cleanup to remove any resources you created in this sublesson.