# Pipeline

An AWS CodePipeline pipeline with its associated IAM role and S3 bucket.

Extends: [Construct](https://docs.aws.amazon.com/cdk/api/v2/docs/constructs.Construct.html) › [Resource](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.Resource.html) › Pipeline
Implements: [IResource](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.IResource.html), [IPipeline](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codepipeline.IPipeline.html), [INotificationRuleSource](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codestarnotifications.INotificationRuleSource.html), [IEnvironmentAware](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.interfaces.IEnvironmentAware.html), IPipelineRef, IConstruct, IDependable

- CloudFormation: [`AWS::CodePipeline::Pipeline`](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-codepipeline-pipeline.html)
- L1 type: [`CfnPipeline`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codepipeline.CfnPipeline.html)
- Source: [`aws-codepipeline/lib/pipeline.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-codepipeline/lib/pipeline.ts#L550)
- Type last changed: v2.234.0 · 8 Jan 2026

## Example

TypeScript:

```ts
// create a pipeline
import * as codecommit from 'aws-cdk-lib/aws-codecommit';

const pipeline = new codepipeline.Pipeline(this, 'Pipeline');

// add a stage
const sourceStage = pipeline.addStage({ stageName: 'Source' });

// add a source action to the stage
declare const repo: codecommit.Repository;
declare const sourceArtifact: codepipeline.Artifact;
sourceStage.addAction(new codepipeline_actions.CodeCommitSourceAction({
  actionName: 'Source',
  output: sourceArtifact,
  repository: repo,
}));

// ... add more stages
```

Python:

```python
# create a pipeline
import aws_cdk.aws_codecommit as codecommit

# add a source action to the stage
# repo: codecommit.Repository
# source_artifact: codepipeline.Artifact

pipeline = codepipeline.Pipeline(self, "Pipeline")

# add a stage
source_stage = pipeline.add_stage(stage_name="Source")
source_stage.add_action(codepipeline_actions.CodeCommitSourceAction(
    action_name="Source",
    output=source_artifact,
    repository=repo
))
```

Java:

```java
// create a pipeline
import software.amazon.awscdk.services.codecommit.*;

// add a source action to the stage
Repository repo;
Artifact sourceArtifact;

Pipeline pipeline = new Pipeline(this, "Pipeline");

// add a stage
IStage sourceStage = pipeline.addStage(StageOptions.builder().stageName("Source").build());
sourceStage.addAction(CodeCommitSourceAction.Builder.create()
        .actionName("Source")
        .output(sourceArtifact)
        .repository(repo)
        .build());
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
// create a pipeline
using Amazon.CDK.AWS.CodeCommit;

// add a source action to the stage
Repository repo;
Artifact sourceArtifact;

var pipeline = new Pipeline(this, "Pipeline");

// add a stage
var sourceStage = pipeline.AddStage(new StageOptions { StageName = "Source" });
sourceStage.AddAction(new CodeCommitSourceAction(new CodeCommitSourceActionProps {
    ActionName = "Source",
    Output = sourceArtifact,
    Repository = repo
}));
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// create a pipeline
import codecommit "github.com/aws/aws-cdk-go/awscdk"

// add a source action to the stage
var repo Repository
var sourceArtifact Artifact

pipeline := codepipeline.NewPipeline(this, jsii.String("Pipeline"))

// add a stage
sourceStage := pipeline.AddStage(&StageOptions{
	StageName: jsii.String("Source"),
})
sourceStage.AddAction(codepipeline_actions.NewCodeCommitSourceAction(&CodeCommitSourceActionProps{
	ActionName: jsii.String("Source"),
	Output: sourceArtifact,
	Repository: repo,
}))
```

## Initializer

TypeScript:

```ts
new Pipeline(scope: Construct, id: string, props?: PipelineProps)
```

Python:

```python
Pipeline(scope: Construct, id: str, props: typing.Optional[PipelineProps] = None)
```

Java:

```java
new Pipeline(Construct scope, String id, PipelineProps props)
```

C# / .NET:

```csharp
new Pipeline(Construct scope, string id, PipelineProps? props = null)
```

Golang:

```go
NewPipeline(Scope Construct, Id *string, Props PipelineProps)
```

## Construct Props

- `artifactBucket`: [IBucket](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.IBucket.html) — The S3 bucket used by this Pipeline to store artifacts.

  **Default:** A new S3 bucket will be created.

- `crossAccountKeys`: boolean — Create KMS keys for cross-account deployments.

  **Default:** false - false if the feature flag `CODEPIPELINE_CROSS_ACCOUNT_KEYS_DEFAULT_VALUE_TO_FALSE` is true, true otherwise

  This controls whether the pipeline is enabled for cross-account deployments.

  By default cross-account deployments are enabled, but this feature requires
  that KMS Customer Master Keys are created which have a cost of $1/month.

  If you do not need cross-account deployments, you can set this to `false` to
  not create those keys and save on that cost (the artifact bucket will be
  encrypted with an AWS-managed key). However, cross-account deployments will
  no longer be possible.

- `crossRegionReplicationBuckets`: { [key: string]: [IBucket](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.IBucket.html) } = None. — A map of region to S3 bucket name used for cross-region CodePipeline.

  For every Action that you specify targeting a different region than the Pipeline itself,
  if you don't provide an explicit Bucket for that region using this property,
  the construct will automatically create a Stack containing an S3 Bucket in that region.

- `enableKeyRotation`: boolean — Enable KMS key rotation for the generated KMS keys.

  **Default:** false (key rotation is disabled)

  By default KMS key rotation is disabled, but will add an additional $1/month
  for each year the key exists when enabled.

- `executionMode`: [ExecutionMode](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codepipeline.ExecutionMode.html) = ExecutionMode.SUPERSEDED — The method that the pipeline will use to handle multiple executions.

- `pipelineName`: string — Name of the pipeline.

  **Default:** AWS CloudFormation generates an ID and uses that for the pipeline name.

- `pipelineType`: [PipelineType](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codepipeline.PipelineType.html) — Type of the pipeline.

  **Default:** PipelineType.V2 if the feature flag `CODEPIPELINE_DEFAULT_PIPELINE_TYPE_TO_V2` is true, PipelineType.V1 otherwise

- `restartExecutionOnUpdate`: boolean = false — Indicates whether to rerun the AWS CodePipeline pipeline after you update it.

- `reuseCrossRegionSupportStacks`: boolean — Reuse the same cross region support stack for all pipelines in the App.

  **Default:** true (Use the same support stack for all pipelines in App)

- `role`: [IRole](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — The IAM role to be assumed by this Pipeline.

  **Default:** a new IAM role will be created.

- `stages`: [StageProps](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codepipeline.StageProps.html)[] = None. — The list of Stages, in order, to create this Pipeline with.

  You can always add more Stages later by calling `Pipeline#addStage`.

- `triggers`: [TriggerProps](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codepipeline.TriggerProps.html)[] — The trigger configuration specifying a type of event, such as Git tags, that starts the pipeline.

  **Default:** No triggers

  When a trigger configuration is specified, default change detection for repository
  and branch commits is disabled.

  `triggers` can only be used when `pipelineType` is set to `PipelineType.V2`.
  You can always add more triggers later by calling `Pipeline#addTrigger`.

- `usePipelineRoleForActions`: boolean = false — Use pipeline service role for actions if no action role configured.

- `variables`: [Variable](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codepipeline.Variable.html)[] — A list that defines the pipeline variables for a pipeline resource.

  **Default:** No variables

  `variables` can only be used when `pipelineType` is set to `PipelineType.V2`.
  You can always add more variables later by calling `Pipeline#addVariable`.

## Properties

- `artifactBucket`: [IBucket](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_s3.IBucket.html) — Bucket used to store output artifacts.

- `crossRegionSupport`: { [key: string]: [CrossRegionSupport](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codepipeline.CrossRegionSupport.html) } — Returns all of the `CrossRegionSupportStack`s that were generated automatically when dealing with Actions that reside in a different region than the Pipeline itself.

- `env`: [ResourceEnvironment](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.interfaces.ResourceEnvironment.html) — The environment this resource belongs to.

  For resources that are created and managed in a Stack (those created by
  creating new class instances like `new Role()`, `new Bucket()`, etc.), this
  is always the same as the environment of the stack they belong to.

  For referenced resources (those obtained from referencing methods like
  `Role.fromRoleArn()`, `Bucket.fromBucketName()`, etc.), they might be
  different than the stack they were imported into.

- `node`: [Node](https://docs.aws.amazon.com/cdk/api/v2/docs/constructs.Node.html) — The tree node.

- `pipelineArn`: string — ARN of this pipeline.

- `pipelineName`: string — The name of the pipeline.

- `pipelineRef`: [PipelineReference](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_codepipeline.PipelineReference.html) — A reference to a Pipeline resource.

- `pipelineVersion`: string — The version of the pipeline.

- `PROPERTY_INJECTION_ID`: string (static) — Uniquely identifies this class.

- `role`: [IRole](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — The IAM role AWS CodePipeline will use to perform actions or assume roles for actions with a more specific IAM role.

- `stack`: [Stack](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.Stack.html) — The stack in which this resource is defined.

- `stageCount`: number — Get the number of Stages in this Pipeline.

- `stages`: [IStage](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codepipeline.IStage.html)[] — Returns the stages that comprise the pipeline.

  **Note**: the returned array is a defensive copy,
  so adding elements to it has no effect.
  Instead, use the `addStage` method if you want to add more stages
  to the pipeline.

## Methods

- `addStage(props: StageOptions): IStage` — Creates a new Stage, and adds it to this Pipeline.

  **Parameters**

  - `props` — the creation properties of the new Stage.

  **Returns:** the newly created Stage

- `addToRolePolicy(statement: PolicyStatement): void` — Adds a statement to the pipeline role.

- `addTrigger(props: TriggerProps): Trigger` — Adds a new Trigger to this Pipeline.

  **Parameters**

  - `props` — Trigger property to add to this Pipeline.

  **Returns:** the newly created trigger

- `addVariable(variable: Variable): Variable` — Adds a new Variable to this Pipeline.

  **Parameters**

  - `variable` — Variable instance to add to this Pipeline.

  **Returns:** the newly created variable

- `applyCrossStackReferenceStrength(strength: ReferenceStrength): void` — Override the cross-stack reference strength for this resource.

  When set, any cross-stack reference to this resource will use the specified
  mechanism instead of the global default determined by the
  `@aws-cdk/core:defaultCrossStackReferences` context key. This is useful for
  selectively weakening specific references to avoid the "deadly embrace" problem
  without changing the app-wide default.

  **Parameters**

  - `strength` — - The reference strength to use for this resource.

- `applyRemovalPolicy(policy: RemovalPolicy): void` — Apply the given removal policy to this resource.

  The Removal Policy controls what happens to this resource when it stops
  being managed by CloudFormation, either because you've removed it from the
  CDK application or because you've made a change that requires the resource
  to be replaced.

  The resource can be deleted (`RemovalPolicy.DESTROY`), or left in your AWS
  account for data recovery and cleanup later (`RemovalPolicy.RETAIN`).

- `bindAsNotificationRuleSource(_scope: Construct): NotificationRuleSourceConfig` — Returns a source configuration for notification rule.

- `fromPipelineArn(scope: Construct, id: string, pipelineArn: string): IPipeline` (static) — Import a pipeline into this app.

  **Parameters**

  - `scope` — the scope into which to import this pipeline.
  - `id` — the logical ID of the returned pipeline construct.
  - `pipelineArn` — The ARN of the pipeline (e.g. `arn:aws:codepipeline:us-east-1:123456789012:MyDemoPipeline`).

- `isConstruct(x: any): boolean` (static) — Checks if `x` is a construct.

  Use this method instead of `instanceof` to properly detect `Construct`
  instances, even when the construct library is symlinked.

  Explanation: in JavaScript, multiple copies of the `constructs` library on
  disk are seen as independent, completely different libraries. As a
  consequence, the class `Construct` in each copy of the `constructs` library
  is seen as a different class, and an instance of one class will not test as
  `instanceof` the other class. `npm install` will not create installations
  like this, but users may manually symlink construct libraries together or
  use a monorepo tool: in those cases, multiple copies of the `constructs`
  library can be accidentally installed, and `instanceof` will behave
  unpredictably. It is safest to avoid using `instanceof`, and using
  this type-testing method instead.

  **Parameters**

  - `x` — Any object.

  **Returns:** true if `x` is an object created from a class which extends `Construct`.

- `isOwnedResource(construct: IConstruct): boolean` (static) — Returns true if the construct was created by CDK, and false otherwise.

- `isResource(construct: IConstruct): boolean` (static) — Check whether the given construct is a Resource.

- `notifyOn(id: string, target: INotificationRuleTarget, options: PipelineNotifyOnOptions): INotificationRule` — Defines a CodeStar notification rule triggered when the pipeline events emitted by you specified, it very similar to `onEvent` API.

  You can also use the methods `notifyOnExecutionStateChange`, `notifyOnAnyStageStateChange`,
  `notifyOnAnyActionStateChange` and `notifyOnAnyManualApprovalStateChange`
  to define rules for these specific event emitted.

- `notifyOnAnyActionStateChange(id: string, target: INotificationRuleTarget, options?: NotificationRuleOptions): INotificationRule` — Define an notification rule triggered by the set of the "Action execution" events emitted from this pipeline.

- `notifyOnAnyManualApprovalStateChange(id: string, target: INotificationRuleTarget, options?: NotificationRuleOptions): INotificationRule` — Define an notification rule triggered by the set of the "Manual approval" events emitted from this pipeline.

- `notifyOnAnyStageStateChange(id: string, target: INotificationRuleTarget, options?: NotificationRuleOptions): INotificationRule` — Define an notification rule triggered by the set of the "Stage execution" events emitted from this pipeline.

- `notifyOnExecutionStateChange(id: string, target: INotificationRuleTarget, options?: NotificationRuleOptions): INotificationRule` — Define an notification rule triggered by the set of the "Pipeline execution" events emitted from this pipeline.

- `onEvent(id: string, options?: OnEventOptions): Rule` — Defines an event rule triggered by this CodePipeline.

  **Parameters**

  - `id` — Identifier for this event handler.
  - `options` — Additional options to pass to the event rule.

- `onStateChange(id: string, options?: OnEventOptions): Rule` — Defines an event rule triggered by the "CodePipeline Pipeline Execution State Change" event emitted from this pipeline.

  **Parameters**

  - `id` — Identifier for this event handler.
  - `options` — Additional options to pass to the event rule.

- `stage(stageName: string): IStage` — Access one of the pipeline's stages by stage name.

- `toString(): string` — Returns a string representation of this construct.

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.
  Use multiple `with()` calls if subsequent mixins should apply to added
  constructs.
