Lesson 3 of 5 AWS CI/CD Services

Automating Releases with AWS CodePipeline

This lesson explains how AWS CodePipeline orchestrates the source, build, test and deploy stages of a release as an automated continuous delivery pipeline.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe how stages, actions and artifacts make up a pipeline.
  • Describe the features that V2 pipelines add, such as triggers with filters and variables.
  • Explain how manual approval actions and notifications control releases.

Stages, actions and artifacts

A CodePipeline pipeline models a release process as a sequence of stages, such as Source, Build, Test and Deploy. Each stage contains one or more actions, and each action is performed by a provider: AWS CodeBuild for builds and tests, AWS CodeDeploy, AWS CloudFormation, Amazon ECS or AWS Elastic Beanstalk for deployments, AWS Lambda for custom steps, and a manual approval action for sign-off. Within a stage, actions with the same runOrder value run in parallel, and actions with a higher value run after them. A stage must succeed before the pipeline moves to the next one, so a failed test stops the release.

Actions exchange files through artifacts. The source action produces an output artifact containing the code; the build action takes it as an input artifact and produces its own output, such as a packaged template, which the deploy action then uses. CodePipeline stores artifacts in an S3 bucket called the artifact store, encrypted with an AWS KMS key.

A pipeline starts when its source changes. Typical sources are GitHub, GitLab and Bitbucket, connected through AWS CodeConnections, AWS CodeCommit, an object key in Amazon S3 and an image tag in Amazon ECR. CodeCommit was closed to new customers in July 2024 but returned to general availability in November 2025. Pipelines should start from events, such as webhooks or EventBridge rules, rather than by periodically polling the source.

The following diagram shows a four-stage pipeline and how its actions exchange artifacts.

A CodePipeline pipeline with Source, Build, Test and Deploy stages. Actions with the same runOrder, such as the two test actions, run in parallel; a higher runOrder, such as the CloudFormation deployment after the manual approval, runs later. Each stage must succeed before the next starts, and actions pass artifacts through an S3 artifact store encrypted with a KMS key.
Stages run one after another; within a stage, runOrder decides which actions run together.
True or false

How pipelines run

Exam skills 3.3.5

Check four facts about CodePipeline stages, actions and approvals.

Log in to try this activity Interactive activities are free with an account.

V2 pipeline features

CodePipeline has two pipeline types. V2 pipelines add features that give finer control over when a pipeline runs and how its stages share data.

Triggers with filters decide which source changes start the pipeline. Instead of running on every push, a V2 pipeline can start only for pushes to particular branches, changes under particular file paths, pull request events or new Git tags, which lets one repository feed several pipelines. Pipeline variables are values defined for the whole pipeline, with defaults that can be overridden when an execution starts, for example the target environment. Output variables are values that an action produces, such as the image tag that a CodeBuild action created, which later actions reference with #{Namespace.Variable}.

The execution mode decides what happens when a new change arrives while a previous execution is still running. In superseded mode, the default, a newer execution can overtake an older one, which is then abandoned. In queued mode, executions run one after another in order. In parallel mode, they run independently at the same time. The following table summarises the features.

FeatureWhat it does
Triggers with filtersStart the pipeline only for certain branches, file paths, pull requests or Git tags
Pipeline variablesValues set at pipeline level and passed to actions
Execution modesSuperseded, queued or parallel: decide what happens when changes arrive mid-run
Output variablesActions, including CodeBuild, export values that later actions read with #{Namespace.Variable}, such as a new image tag
Sort into groups

Which V2 feature?

Exam skills 3.3.5

Choose the V2 pipeline feature for each requirement.

Log in to try this activity Interactive activities are free with an account.

Approvals and notifications

A manual approval action pauses a pipeline until a person approves or rejects it, typically before deployment to production. The action can publish a message to an Amazon SNS topic so reviewers are notified, and it can include a URL for them to review, such as a test environment. Approving requires the codepipeline:PutApprovalResult permission, which can be limited to particular people. If nobody responds within seven days, the action fails.

CodePipeline emits an Amazon EventBridge event whenever a pipeline, stage or action changes state, for example to STARTED, SUCCEEDED or FAILED. An EventBridge rule that matches failed executions can notify a team or start follow-up automation, such as opening a ticket. For simple notifications, CodePipeline notification rules send the same events to SNS topics or chat channels without writing an event pattern.

Worked example

Designing a release pipeline

A release pipeline is composed of stages, each with a specific purpose. The following table describes the action and purpose of each stage in a typical design.

StageActionPurpose
SourceGitHub via CodeConnections, branch mainStart on every merge
BuildCodeBuild: test, package, sam packageProduce one artifact
Deploy-TestCloudFormation deploy to the test accountRun the artifact in a real environment
TestCodeBuild integration tests against the test stackProve it works
ApprovalManual approval with SNS notificationHuman sign-off for production
Deploy-ProdCloudFormation deploy to production with canary traffic shiftingRelease safely

The same artifact built once flows through every stage, so production runs exactly what was tested. Exported variables from the build (such as the version number) are passed to later actions with the #{BuildVariables.VERSION} syntax.

Check yourself

How can a pipeline wait before production until someone confirms that staging looks correct?

Show answer

Add a manual approval action before the production stage. The pipeline pauses until the action is approved or rejected, and an SNS topic can notify the approvers.

Exam Tips

Remember for the exam

  • To require sign-off before deploying to production, add a manual approval action.
  • To be notified when a pipeline fails, create an EventBridge rule on pipeline state changes.
  • To pass the built image tag to the deploy action, use CodeBuild exported variables.
  • To run the pipeline only for changes in one folder, use a V2 trigger with a file path filter.