# AWS CodePipeline Construct Library
<!--BEGIN STABILITY BANNER-->---
![cfn-resources: Stable](https://img.shields.io/badge/cfn--resources-stable-success.svg?style=for-the-badge)
![cdk-constructs: Stable](https://img.shields.io/badge/cdk--constructs-stable-success.svg?style=for-the-badge)
---
<!--END STABILITY BANNER-->
## Pipeline
To construct an empty Pipeline:
```python
# Construct an empty Pipeline
pipeline = codepipeline.Pipeline(self, "MyFirstPipeline")
```
To give the Pipeline a nice, human-readable name:
```python
# Give the Pipeline a nice, human-readable name
pipeline = codepipeline.Pipeline(self, "MyFirstPipeline",
pipeline_name="MyPipeline"
)
```
Be aware that in the default configuration, the `Pipeline` construct creates
an AWS Key Management Service (AWS KMS) Customer Master Key (CMK) for you to
encrypt the artifacts in the artifact bucket, which incurs a cost of
**$1/month**. This default configuration is necessary to allow cross-account
actions.
If you do not intend to perform cross-account deployments, you can disable
the creation of the Customer Master Keys by passing `crossAccountKeys: false`
when defining the Pipeline:
```python
# Don't create Customer Master Keys
pipeline = codepipeline.Pipeline(self, "MyFirstPipeline",
cross_account_keys=False
)
```
If you want to enable key rotation for the generated KMS keys,
you can configure it by passing `enableKeyRotation: true` when creating the pipeline.
Note that key rotation will incur an additional cost of **$1/month**.
```python
# Enable key rotation for the generated KMS key
pipeline = codepipeline.Pipeline(self, "MyFirstPipeline",
# ...
enable_key_rotation=True
)
```
## Stages
You can provide Stages when creating the Pipeline:
```python
# Provide a Stage when creating a pipeline
pipeline = codepipeline.Pipeline(self, "MyFirstPipeline",
stages=[codepipeline.StageProps(
stage_name="Source",
actions=[]
)
]
)
```
Or append a Stage to an existing Pipeline:
```python
# Append a Stage to an existing Pipeline
# pipeline: codepipeline.Pipeline
source_stage = pipeline.add_stage(
stage_name="Source",
actions=[]
)
```
You can insert the new Stage at an arbitrary point in the Pipeline:
```python
# Insert a new Stage at an arbitrary point
# pipeline: codepipeline.Pipeline
# another_stage: codepipeline.IStage
# yet_another_stage: codepipeline.IStage
some_stage = pipeline.add_stage(
stage_name="SomeStage",
placement=codepipeline.StagePlacement(
# note: you can only specify one of the below properties
right_before=another_stage,
just_after=yet_another_stage
)
)
```
You can disable transition to a Stage:
```python
# Disable transition to a stage
# pipeline: codepipeline.Pipeline
some_stage = pipeline.add_stage(
stage_name="SomeStage",
transition_to_enabled=False,
transition_disabled_reason="Manual transition only"
)
```
This is useful if you don't want every executions of the pipeline to flow into
this stage automatically. The transition can then be "manually" enabled later on.
## Actions
Actions live in a separate package, `@aws-cdk/aws-codepipeline-actions`.
To add an Action to a Stage, you can provide it when creating the Stage,
in the `actions` property,
or you can use the `IStage.addAction()` method to mutate an existing Stage:
```python
# Use the `IStage.addAction()` method to mutate an existing Stage.
# source_stage: codepipeline.IStage
# some_action: codepipeline.Action
source_stage.add_action(some_action)
```
## Custom Action Registration
To make your own custom CodePipeline Action requires registering the action provider. Look to the `JenkinsProvider` in `@aws-cdk/aws-codepipeline-actions` for an implementation example.
```python
# Make a custom CodePipeline Action
codepipeline.CustomActionRegistration(self, "GenericGitSourceProviderResource",
category=codepipeline.ActionCategory.SOURCE,
artifact_bounds=codepipeline.ActionArtifactBounds(min_inputs=0, max_inputs=0, min_outputs=1, max_outputs=1),
provider="GenericGitSource",
version="1",
entity_url="https://docs.aws.amazon.com/codepipeline/latest/userguide/actions-create-custom-action.html",
execution_url="https://docs.aws.amazon.com/codepipeline/latest/userguide/actions-create-custom-action.html",
action_properties=[codepipeline.CustomActionProperty(
name="Branch",
required=True,
key=False,
secret=False,
queryable=False,
description="Git branch to pull",
type="String"
), codepipeline.CustomActionProperty(
name="GitUrl",
required=True,
key=False,
secret=False,
queryable=False,
description="SSH git clone URL",
type="String"
)
]
)
```
## Cross-account CodePipelines
> Cross-account Pipeline actions require that the Pipeline has *not* been
> created with `crossAccountKeys: false`.
Most pipeline Actions accept an AWS resource object to operate on. For example:
* `S3DeployAction` accepts an `s3.IBucket`.
* `CodeBuildAction` accepts a `codebuild.IProject`.
* etc.
These resources can be either newly defined (`new s3.Bucket(...)`) or imported
(`s3.Bucket.fromBucketAttributes(...)`) and identify the resource that should
be changed.
These resources can be in different accounts than the pipeline itself. For
example, the following action deploys to an imported S3 bucket from a
different account:
```python
# Deploy an imported S3 bucket from a different account
# stage: codepipeline.IStage
# input: codepipeline.Artifact
stage.add_action(codepipeline_actions.S3DeployAction(
bucket=s3.Bucket.from_bucket_attributes(self, "Bucket",
account="123456789012"
),
input=input,
action_name="s3-deploy-action"
))
```
Actions that don't accept a resource object accept an explicit `account` parameter:
```python
# Actions that don't accept a resource objet accept an explicit `account` parameter
# stage: codepipeline.IStage
# template_path: codepipeline.ArtifactPath
stage.add_action(codepipeline_actions.CloudFormationCreateUpdateStackAction(
account="123456789012",
template_path=template_path,
admin_permissions=False,
stack_name=Stack.of(self).stack_name,
action_name="cloudformation-create-update"
))
```
The `Pipeline` construct automatically defines an **IAM Role** for you in the
target account which the pipeline will assume to perform that action. This
Role will be defined in a **support stack** named
`<PipelineStackName>-support-<account>`, that will automatically be deployed
before the stack containing the pipeline.
If you do not want to use the generated role, you can also explicitly pass a
`role` when creating the action. In that case, the action will operate in the
account the role belongs to:
```python
# Explicitly pass in a `role` when creating an action.
# stage: codepipeline.IStage
# template_path: codepipeline.ArtifactPath
stage.add_action(codepipeline_actions.CloudFormationCreateUpdateStackAction(
template_path=template_path,
admin_permissions=False,
stack_name=Stack.of(self).stack_name,
action_name="cloudformation-create-update",
# ...
role=iam.Role.from_role_arn(self, "ActionRole", "...")
))
```
## Cross-region CodePipelines
Similar to how you set up a cross-account Action, the AWS resource object you
pass to actions can also be in different *Regions*. For example, the
following Action deploys to an imported S3 bucket from a different Region:
```python
# Deploy to an imported S3 bucket from a different Region.
# stage: codepipeline.IStage
# input: codepipeline.Artifact
stage.add_action(codepipeline_actions.S3DeployAction(
bucket=s3.Bucket.from_bucket_attributes(self, "Bucket",
region="us-west-1"
),
input=input,
action_name="s3-deploy-action"
))
```
Actions that don't take an AWS resource will accept an explicit `region`
parameter:
```python
# Actions that don't take an AWS resource will accept an explicit `region` parameter.
# stage: codepipeline.IStage
# template_path: codepipeline.ArtifactPath
stage.add_action(codepipeline_actions.CloudFormationCreateUpdateStackAction(
template_path=template_path,
admin_permissions=False,
stack_name=Stack.of(self).stack_name,
action_name="cloudformation-create-update",
# ...
region="us-west-1"
))
```
The `Pipeline` construct automatically defines a **replication bucket** for
you in the target region, which the pipeline will replicate artifacts to and
from. This Bucket will be defined in a **support stack** named
`<PipelineStackName>-support-<region>`, that will automatically be deployed
before the stack containing the pipeline.
If you don't want to use these support stacks, and already have buckets in
place to serve as replication buckets, you can supply these at Pipeline definition
time using the `crossRegionReplicationBuckets` parameter. Example:
```python
# Supply replication buckets for the Pipeline instead of using the generated support stack
pipeline = codepipeline.Pipeline(self, "MyFirstPipeline",
# ...
cross_region_replication_buckets={
# note that a physical name of the replication Bucket must be known at synthesis time
"us-west-1": s3.Bucket.from_bucket_attributes(self, "UsWest1ReplicationBucket",
bucket_name="my-us-west-1-replication-bucket",
# optional KMS key
encryption_key=kms.Key.from_key_arn(self, "UsWest1ReplicationKey", "arn:aws:kms:us-west-1:123456789012:key/1234-5678-9012")
)
}
)
```
See [the AWS docs here](https://docs.aws.amazon.com/codepipeline/latest/userguide/actions-create-cross-region.html)
for more information on cross-region CodePipelines.
### Creating an encrypted replication bucket
If you're passing a replication bucket created in a different stack,
like this:
```python
# Passing a replication bucket created in a different stack.
app = App()
replication_stack = Stack(app, "ReplicationStack",
env=Environment(
region="us-west-1"
)
)
key = kms.Key(replication_stack, "ReplicationKey")
replication_bucket = s3.Bucket(replication_stack, "ReplicationBucket",
# like was said above - replication buckets need a set physical name
bucket_name=PhysicalName.GENERATE_IF_NEEDED,
encryption_key=key
)
# later...
codepipeline.Pipeline(replication_stack, "Pipeline",
cross_region_replication_buckets={
"us-west-1": replication_bucket
}
)
```
When trying to encrypt it
(and note that if any of the cross-region actions happen to be cross-account as well,
the bucket *has to* be encrypted - otherwise the pipeline will fail at runtime),
you cannot use a key directly - KMS keys don't have physical names,
and so you can't reference them across environments.
In this case, you need to use an alias in place of the key when creating the bucket:
```python
# Passing an encrypted replication bucket created in a different stack.
app = App()
replication_stack = Stack(app, "ReplicationStack",
env=Environment(
region="us-west-1"
)
)
key = kms.Key(replication_stack, "ReplicationKey")
alias = kms.Alias(replication_stack, "ReplicationAlias",
# aliasName is required
alias_name=PhysicalName.GENERATE_IF_NEEDED,
target_key=key
)
replication_bucket = s3.Bucket(replication_stack, "ReplicationBucket",
bucket_name=PhysicalName.GENERATE_IF_NEEDED,
encryption_key=alias
)
```
## Variables
The library supports the CodePipeline Variables feature.
Each action class that emits variables has a separate variables interface,
accessed as a property of the action instance called `variables`.
You instantiate the action class and assign it to a local variable;
when you want to use a variable in the configuration of a different action,
you access the appropriate property of the interface returned from `variables`,
which represents a single variable.
Example:
```python
# MyAction is some action type that produces variables, like EcrSourceAction
my_action = MyAction(
# ...
action_name="myAction"
)
OtherAction(
# ...
config=my_action.variables.my_variable,
action_name="otherAction"
)
```
The namespace name that will be used will be automatically generated by the pipeline construct,
based on the stage and action name;
you can pass a custom name when creating the action instance:
```python
# MyAction is some action type that produces variables, like EcrSourceAction
my_action = MyAction(
# ...
variables_namespace="MyNamespace",
action_name="myAction"
)
```
There are also global variables available,
not tied to any action;
these are accessed through static properties of the `GlobalVariables` class:
```python
# OtherAction is some action type that produces variables, like EcrSourceAction
OtherAction(
# ...
config=codepipeline.GlobalVariables.execution_id,
action_name="otherAction"
)
```
Check the documentation of the `@aws-cdk/aws-codepipeline-actions`
for details on how to use the variables for each action class.
See the [CodePipeline documentation](https://docs.aws.amazon.com/codepipeline/latest/userguide/reference-variables.html)
for more details on how to use the variables feature.
## Events
### Using a pipeline as an event target
A pipeline can be used as a target for a CloudWatch event rule:
```python
# A pipeline being used as a target for a CloudWatch event rule.
import aws_cdk.aws_events_targets as targets
import aws_cdk.aws_events as events
# pipeline: codepipeline.Pipeline
# kick off the pipeline every day
rule = events.Rule(self, "Daily",
schedule=events.Schedule.rate(Duration.days(1))
)
rule.add_target(targets.CodePipeline(pipeline))
```
When a pipeline is used as an event target, the
"codepipeline:StartPipelineExecution" permission is granted to the AWS
CloudWatch Events service.
### Event sources
Pipelines emit CloudWatch events. To define event rules for events emitted by
the pipeline, stages or action, use the `onXxx` methods on the respective
construct:
```python
# Define event rules for events emitted by the pipeline
import aws_cdk.aws_events as events
# my_pipeline: codepipeline.Pipeline
# my_stage: codepipeline.IStage
# my_action: codepipeline.Action
# target: events.IRuleTarget
my_pipeline.on_state_change("MyPipelineStateChange", target=target)
my_stage.on_state_change("MyStageStateChange", target)
my_action.on_state_change("MyActionStateChange", target)
```
## CodeStar Notifications
To define CodeStar Notification rules for Pipelines, use one of the `notifyOnXxx()` methods.
They are very similar to `onXxx()` methods for CloudWatch events:
```python
# Define CodeStar Notification rules for Pipelines
import aws_cdk.aws_chatbot as chatbot
# pipeline: codepipeline.Pipeline
target = chatbot.SlackChannelConfiguration(self, "MySlackChannel",
slack_channel_configuration_name="YOUR_CHANNEL_NAME",
slack_workspace_id="YOUR_SLACK_WORKSPACE_ID",
slack_channel_id="YOUR_SLACK_CHANNEL_ID"
)
rule = pipeline.notify_on_execution_state_change("NotifyOnExecutionStateChange", target)
```
Raw data
{
"_id": null,
"home_page": "https://github.com/aws/aws-cdk",
"name": "aws-cdk.aws-codepipeline",
"maintainer": "",
"docs_url": null,
"requires_python": "~=3.7",
"maintainer_email": "",
"keywords": "",
"author": "Amazon Web Services",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/ec/60/b4c71fc77c310356de5ad6efe3e729c379cad7f32a3b0a9675b8ad87dbc9/aws-cdk.aws-codepipeline-1.203.0.tar.gz",
"platform": null,
"description": "# AWS CodePipeline Construct Library\n\n<!--BEGIN STABILITY BANNER-->---\n\n\n![cfn-resources: Stable](https://img.shields.io/badge/cfn--resources-stable-success.svg?style=for-the-badge)\n\n![cdk-constructs: Stable](https://img.shields.io/badge/cdk--constructs-stable-success.svg?style=for-the-badge)\n\n---\n<!--END STABILITY BANNER-->\n\n## Pipeline\n\nTo construct an empty Pipeline:\n\n```python\n# Construct an empty Pipeline\npipeline = codepipeline.Pipeline(self, \"MyFirstPipeline\")\n```\n\nTo give the Pipeline a nice, human-readable name:\n\n```python\n# Give the Pipeline a nice, human-readable name\npipeline = codepipeline.Pipeline(self, \"MyFirstPipeline\",\n pipeline_name=\"MyPipeline\"\n)\n```\n\nBe aware that in the default configuration, the `Pipeline` construct creates\nan AWS Key Management Service (AWS KMS) Customer Master Key (CMK) for you to\nencrypt the artifacts in the artifact bucket, which incurs a cost of\n**$1/month**. This default configuration is necessary to allow cross-account\nactions.\n\nIf you do not intend to perform cross-account deployments, you can disable\nthe creation of the Customer Master Keys by passing `crossAccountKeys: false`\nwhen defining the Pipeline:\n\n```python\n# Don't create Customer Master Keys\npipeline = codepipeline.Pipeline(self, \"MyFirstPipeline\",\n cross_account_keys=False\n)\n```\n\nIf you want to enable key rotation for the generated KMS keys,\nyou can configure it by passing `enableKeyRotation: true` when creating the pipeline.\nNote that key rotation will incur an additional cost of **$1/month**.\n\n```python\n# Enable key rotation for the generated KMS key\npipeline = codepipeline.Pipeline(self, \"MyFirstPipeline\",\n # ...\n enable_key_rotation=True\n)\n```\n\n## Stages\n\nYou can provide Stages when creating the Pipeline:\n\n```python\n# Provide a Stage when creating a pipeline\npipeline = codepipeline.Pipeline(self, \"MyFirstPipeline\",\n stages=[codepipeline.StageProps(\n stage_name=\"Source\",\n actions=[]\n )\n ]\n)\n```\n\nOr append a Stage to an existing Pipeline:\n\n```python\n# Append a Stage to an existing Pipeline\n# pipeline: codepipeline.Pipeline\n\nsource_stage = pipeline.add_stage(\n stage_name=\"Source\",\n actions=[]\n)\n```\n\nYou can insert the new Stage at an arbitrary point in the Pipeline:\n\n```python\n# Insert a new Stage at an arbitrary point\n# pipeline: codepipeline.Pipeline\n# another_stage: codepipeline.IStage\n# yet_another_stage: codepipeline.IStage\n\n\nsome_stage = pipeline.add_stage(\n stage_name=\"SomeStage\",\n placement=codepipeline.StagePlacement(\n # note: you can only specify one of the below properties\n right_before=another_stage,\n just_after=yet_another_stage\n )\n)\n```\n\nYou can disable transition to a Stage:\n\n```python\n# Disable transition to a stage\n# pipeline: codepipeline.Pipeline\n\n\nsome_stage = pipeline.add_stage(\n stage_name=\"SomeStage\",\n transition_to_enabled=False,\n transition_disabled_reason=\"Manual transition only\"\n)\n```\n\nThis is useful if you don't want every executions of the pipeline to flow into\nthis stage automatically. The transition can then be \"manually\" enabled later on.\n\n## Actions\n\nActions live in a separate package, `@aws-cdk/aws-codepipeline-actions`.\n\nTo add an Action to a Stage, you can provide it when creating the Stage,\nin the `actions` property,\nor you can use the `IStage.addAction()` method to mutate an existing Stage:\n\n```python\n# Use the `IStage.addAction()` method to mutate an existing Stage.\n# source_stage: codepipeline.IStage\n# some_action: codepipeline.Action\n\nsource_stage.add_action(some_action)\n```\n\n## Custom Action Registration\n\nTo make your own custom CodePipeline Action requires registering the action provider. Look to the `JenkinsProvider` in `@aws-cdk/aws-codepipeline-actions` for an implementation example.\n\n```python\n# Make a custom CodePipeline Action\ncodepipeline.CustomActionRegistration(self, \"GenericGitSourceProviderResource\",\n category=codepipeline.ActionCategory.SOURCE,\n artifact_bounds=codepipeline.ActionArtifactBounds(min_inputs=0, max_inputs=0, min_outputs=1, max_outputs=1),\n provider=\"GenericGitSource\",\n version=\"1\",\n entity_url=\"https://docs.aws.amazon.com/codepipeline/latest/userguide/actions-create-custom-action.html\",\n execution_url=\"https://docs.aws.amazon.com/codepipeline/latest/userguide/actions-create-custom-action.html\",\n action_properties=[codepipeline.CustomActionProperty(\n name=\"Branch\",\n required=True,\n key=False,\n secret=False,\n queryable=False,\n description=\"Git branch to pull\",\n type=\"String\"\n ), codepipeline.CustomActionProperty(\n name=\"GitUrl\",\n required=True,\n key=False,\n secret=False,\n queryable=False,\n description=\"SSH git clone URL\",\n type=\"String\"\n )\n ]\n)\n```\n\n## Cross-account CodePipelines\n\n> Cross-account Pipeline actions require that the Pipeline has *not* been\n> created with `crossAccountKeys: false`.\n\nMost pipeline Actions accept an AWS resource object to operate on. For example:\n\n* `S3DeployAction` accepts an `s3.IBucket`.\n* `CodeBuildAction` accepts a `codebuild.IProject`.\n* etc.\n\nThese resources can be either newly defined (`new s3.Bucket(...)`) or imported\n(`s3.Bucket.fromBucketAttributes(...)`) and identify the resource that should\nbe changed.\n\nThese resources can be in different accounts than the pipeline itself. For\nexample, the following action deploys to an imported S3 bucket from a\ndifferent account:\n\n```python\n# Deploy an imported S3 bucket from a different account\n# stage: codepipeline.IStage\n# input: codepipeline.Artifact\n\nstage.add_action(codepipeline_actions.S3DeployAction(\n bucket=s3.Bucket.from_bucket_attributes(self, \"Bucket\",\n account=\"123456789012\"\n ),\n input=input,\n action_name=\"s3-deploy-action\"\n))\n```\n\nActions that don't accept a resource object accept an explicit `account` parameter:\n\n```python\n# Actions that don't accept a resource objet accept an explicit `account` parameter\n# stage: codepipeline.IStage\n# template_path: codepipeline.ArtifactPath\n\nstage.add_action(codepipeline_actions.CloudFormationCreateUpdateStackAction(\n account=\"123456789012\",\n template_path=template_path,\n admin_permissions=False,\n stack_name=Stack.of(self).stack_name,\n action_name=\"cloudformation-create-update\"\n))\n```\n\nThe `Pipeline` construct automatically defines an **IAM Role** for you in the\ntarget account which the pipeline will assume to perform that action. This\nRole will be defined in a **support stack** named\n`<PipelineStackName>-support-<account>`, that will automatically be deployed\nbefore the stack containing the pipeline.\n\nIf you do not want to use the generated role, you can also explicitly pass a\n`role` when creating the action. In that case, the action will operate in the\naccount the role belongs to:\n\n```python\n# Explicitly pass in a `role` when creating an action.\n# stage: codepipeline.IStage\n# template_path: codepipeline.ArtifactPath\n\nstage.add_action(codepipeline_actions.CloudFormationCreateUpdateStackAction(\n template_path=template_path,\n admin_permissions=False,\n stack_name=Stack.of(self).stack_name,\n action_name=\"cloudformation-create-update\",\n # ...\n role=iam.Role.from_role_arn(self, \"ActionRole\", \"...\")\n))\n```\n\n## Cross-region CodePipelines\n\nSimilar to how you set up a cross-account Action, the AWS resource object you\npass to actions can also be in different *Regions*. For example, the\nfollowing Action deploys to an imported S3 bucket from a different Region:\n\n```python\n# Deploy to an imported S3 bucket from a different Region.\n# stage: codepipeline.IStage\n# input: codepipeline.Artifact\n\nstage.add_action(codepipeline_actions.S3DeployAction(\n bucket=s3.Bucket.from_bucket_attributes(self, \"Bucket\",\n region=\"us-west-1\"\n ),\n input=input,\n action_name=\"s3-deploy-action\"\n))\n```\n\nActions that don't take an AWS resource will accept an explicit `region`\nparameter:\n\n```python\n# Actions that don't take an AWS resource will accept an explicit `region` parameter.\n# stage: codepipeline.IStage\n# template_path: codepipeline.ArtifactPath\n\nstage.add_action(codepipeline_actions.CloudFormationCreateUpdateStackAction(\n template_path=template_path,\n admin_permissions=False,\n stack_name=Stack.of(self).stack_name,\n action_name=\"cloudformation-create-update\",\n # ...\n region=\"us-west-1\"\n))\n```\n\nThe `Pipeline` construct automatically defines a **replication bucket** for\nyou in the target region, which the pipeline will replicate artifacts to and\nfrom. This Bucket will be defined in a **support stack** named\n`<PipelineStackName>-support-<region>`, that will automatically be deployed\nbefore the stack containing the pipeline.\n\nIf you don't want to use these support stacks, and already have buckets in\nplace to serve as replication buckets, you can supply these at Pipeline definition\ntime using the `crossRegionReplicationBuckets` parameter. Example:\n\n```python\n# Supply replication buckets for the Pipeline instead of using the generated support stack\npipeline = codepipeline.Pipeline(self, \"MyFirstPipeline\",\n # ...\n\n cross_region_replication_buckets={\n # note that a physical name of the replication Bucket must be known at synthesis time\n \"us-west-1\": s3.Bucket.from_bucket_attributes(self, \"UsWest1ReplicationBucket\",\n bucket_name=\"my-us-west-1-replication-bucket\",\n # optional KMS key\n encryption_key=kms.Key.from_key_arn(self, \"UsWest1ReplicationKey\", \"arn:aws:kms:us-west-1:123456789012:key/1234-5678-9012\")\n )\n }\n)\n```\n\nSee [the AWS docs here](https://docs.aws.amazon.com/codepipeline/latest/userguide/actions-create-cross-region.html)\nfor more information on cross-region CodePipelines.\n\n### Creating an encrypted replication bucket\n\nIf you're passing a replication bucket created in a different stack,\nlike this:\n\n```python\n# Passing a replication bucket created in a different stack.\napp = App()\nreplication_stack = Stack(app, \"ReplicationStack\",\n env=Environment(\n region=\"us-west-1\"\n )\n)\nkey = kms.Key(replication_stack, \"ReplicationKey\")\nreplication_bucket = s3.Bucket(replication_stack, \"ReplicationBucket\",\n # like was said above - replication buckets need a set physical name\n bucket_name=PhysicalName.GENERATE_IF_NEEDED,\n encryption_key=key\n)\n\n# later...\ncodepipeline.Pipeline(replication_stack, \"Pipeline\",\n cross_region_replication_buckets={\n \"us-west-1\": replication_bucket\n }\n)\n```\n\nWhen trying to encrypt it\n(and note that if any of the cross-region actions happen to be cross-account as well,\nthe bucket *has to* be encrypted - otherwise the pipeline will fail at runtime),\nyou cannot use a key directly - KMS keys don't have physical names,\nand so you can't reference them across environments.\n\nIn this case, you need to use an alias in place of the key when creating the bucket:\n\n```python\n# Passing an encrypted replication bucket created in a different stack.\napp = App()\nreplication_stack = Stack(app, \"ReplicationStack\",\n env=Environment(\n region=\"us-west-1\"\n )\n)\nkey = kms.Key(replication_stack, \"ReplicationKey\")\nalias = kms.Alias(replication_stack, \"ReplicationAlias\",\n # aliasName is required\n alias_name=PhysicalName.GENERATE_IF_NEEDED,\n target_key=key\n)\nreplication_bucket = s3.Bucket(replication_stack, \"ReplicationBucket\",\n bucket_name=PhysicalName.GENERATE_IF_NEEDED,\n encryption_key=alias\n)\n```\n\n## Variables\n\nThe library supports the CodePipeline Variables feature.\nEach action class that emits variables has a separate variables interface,\naccessed as a property of the action instance called `variables`.\nYou instantiate the action class and assign it to a local variable;\nwhen you want to use a variable in the configuration of a different action,\nyou access the appropriate property of the interface returned from `variables`,\nwhich represents a single variable.\nExample:\n\n```python\n# MyAction is some action type that produces variables, like EcrSourceAction\nmy_action = MyAction(\n # ...\n action_name=\"myAction\"\n)\nOtherAction(\n # ...\n config=my_action.variables.my_variable,\n action_name=\"otherAction\"\n)\n```\n\nThe namespace name that will be used will be automatically generated by the pipeline construct,\nbased on the stage and action name;\nyou can pass a custom name when creating the action instance:\n\n```python\n# MyAction is some action type that produces variables, like EcrSourceAction\nmy_action = MyAction(\n # ...\n variables_namespace=\"MyNamespace\",\n action_name=\"myAction\"\n)\n```\n\nThere are also global variables available,\nnot tied to any action;\nthese are accessed through static properties of the `GlobalVariables` class:\n\n```python\n# OtherAction is some action type that produces variables, like EcrSourceAction\nOtherAction(\n # ...\n config=codepipeline.GlobalVariables.execution_id,\n action_name=\"otherAction\"\n)\n```\n\nCheck the documentation of the `@aws-cdk/aws-codepipeline-actions`\nfor details on how to use the variables for each action class.\n\nSee the [CodePipeline documentation](https://docs.aws.amazon.com/codepipeline/latest/userguide/reference-variables.html)\nfor more details on how to use the variables feature.\n\n## Events\n\n### Using a pipeline as an event target\n\nA pipeline can be used as a target for a CloudWatch event rule:\n\n```python\n# A pipeline being used as a target for a CloudWatch event rule.\nimport aws_cdk.aws_events_targets as targets\nimport aws_cdk.aws_events as events\n\n# pipeline: codepipeline.Pipeline\n\n\n# kick off the pipeline every day\nrule = events.Rule(self, \"Daily\",\n schedule=events.Schedule.rate(Duration.days(1))\n)\nrule.add_target(targets.CodePipeline(pipeline))\n```\n\nWhen a pipeline is used as an event target, the\n\"codepipeline:StartPipelineExecution\" permission is granted to the AWS\nCloudWatch Events service.\n\n### Event sources\n\nPipelines emit CloudWatch events. To define event rules for events emitted by\nthe pipeline, stages or action, use the `onXxx` methods on the respective\nconstruct:\n\n```python\n# Define event rules for events emitted by the pipeline\nimport aws_cdk.aws_events as events\n\n# my_pipeline: codepipeline.Pipeline\n# my_stage: codepipeline.IStage\n# my_action: codepipeline.Action\n# target: events.IRuleTarget\n\nmy_pipeline.on_state_change(\"MyPipelineStateChange\", target=target)\nmy_stage.on_state_change(\"MyStageStateChange\", target)\nmy_action.on_state_change(\"MyActionStateChange\", target)\n```\n\n## CodeStar Notifications\n\nTo define CodeStar Notification rules for Pipelines, use one of the `notifyOnXxx()` methods.\nThey are very similar to `onXxx()` methods for CloudWatch events:\n\n```python\n# Define CodeStar Notification rules for Pipelines\nimport aws_cdk.aws_chatbot as chatbot\n\n# pipeline: codepipeline.Pipeline\n\ntarget = chatbot.SlackChannelConfiguration(self, \"MySlackChannel\",\n slack_channel_configuration_name=\"YOUR_CHANNEL_NAME\",\n slack_workspace_id=\"YOUR_SLACK_WORKSPACE_ID\",\n slack_channel_id=\"YOUR_SLACK_CHANNEL_ID\"\n)\nrule = pipeline.notify_on_execution_state_change(\"NotifyOnExecutionStateChange\", target)\n```\n\n\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "Better interface to AWS Code Pipeline",
"version": "1.203.0",
"project_urls": {
"Homepage": "https://github.com/aws/aws-cdk",
"Source": "https://github.com/aws/aws-cdk.git"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f1aef1dba7474b81d5c400c0f73bd5e9c8e7b62a5d49e27ec16139b77e8d9df6",
"md5": "f752e653e8baede6eac166ad3fd26e24",
"sha256": "da375548729fb05cf3df614a28b280629272e63012769625e2b47e37c86b7d52"
},
"downloads": -1,
"filename": "aws_cdk.aws_codepipeline-1.203.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f752e653e8baede6eac166ad3fd26e24",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "~=3.7",
"size": 278343,
"upload_time": "2023-05-31T22:53:42",
"upload_time_iso_8601": "2023-05-31T22:53:42.873775Z",
"url": "https://files.pythonhosted.org/packages/f1/ae/f1dba7474b81d5c400c0f73bd5e9c8e7b62a5d49e27ec16139b77e8d9df6/aws_cdk.aws_codepipeline-1.203.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ec60b4c71fc77c310356de5ad6efe3e729c379cad7f32a3b0a9675b8ad87dbc9",
"md5": "ae3cbb9703ca743829d94c68bccecd6f",
"sha256": "6e90ddd5e01cbed8dee5f05f296dda5de197373b50eb744c97223711ccf71a8c"
},
"downloads": -1,
"filename": "aws-cdk.aws-codepipeline-1.203.0.tar.gz",
"has_sig": false,
"md5_digest": "ae3cbb9703ca743829d94c68bccecd6f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "~=3.7",
"size": 279434,
"upload_time": "2023-05-31T23:01:27",
"upload_time_iso_8601": "2023-05-31T23:01:27.373950Z",
"url": "https://files.pythonhosted.org/packages/ec/60/b4c71fc77c310356de5ad6efe3e729c379cad7f32a3b0a9675b8ad87dbc9/aws-cdk.aws-codepipeline-1.203.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-05-31 23:01:27",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "aws",
"github_project": "aws-cdk",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "aws-cdk.aws-codepipeline"
}