Better interface to AWS Code Pipeline
Project description
AWS CodePipeline Construct Library
Pipeline
To construct an empty Pipeline:
import codepipeline = require('@aws-cdk/aws-codepipeline');
const pipeline = new codepipeline.Pipeline(this, 'MyFirstPipeline');
To give the Pipeline a nice, human-readable name:
const pipeline = new codepipeline.Pipeline(this, 'MyFirstPipeline', {
pipelineName: 'MyPipeline',
});
Stages
You can provide Stages when creating the Pipeline:
const pipeline = new codepipeline.Pipeline(this, 'MyFirstPipeline', {
stages: [
{
name: 'Source',
actions: [
// see below...
],
},
],
});
Or append a Stage to an existing Pipeline:
const sourceStage = pipeline.addStage({
name: 'Source',
actions: [ // optional property
// see below...
],
});
You can insert the new Stage at an arbitrary point in the Pipeline:
const someStage = pipeline.addStage({
name: 'SomeStage',
placement: {
// note: you can only specify one of the below properties
rightBefore: anotherStage,
justAfter: anotherStage,
atIndex: 3, // indexing starts at 0
// pipeline.stageCount returns the number of Stages currently in the Pipeline
}
});
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:
sourceStage.addAction(someAction);
Cross-region CodePipelines
You can also use the cross-region feature to deploy resources (currently, only CloudFormation Stacks are supported) into a different region than your Pipeline is in.
It works like this:
const pipeline = new codepipeline.Pipeline(this, 'MyFirstPipeline', {
// ...
crossRegionReplicationBuckets: {
'us-west-1': 'my-us-west-1-replication-bucket',
},
});
// later in the code...
new codepipeline_actions.CloudFormationCreateUpdateStackAction({
actionName: 'CFN_US_West_1',
// ...
region: 'us-west-1',
});
This way, the CFN_US_West_1
Action will operate in the us-west-1
region,
regardless of which region your Pipeline is in.
If you don't provide a bucket name for a region (other than the Pipeline's region)
that you're using for an Action with the crossRegionReplicationBuckets
property,
there will be a new Stack, named aws-cdk-codepipeline-cross-region-scaffolding-<region>
,
defined for you, containing a replication Bucket.
Note that you have to make sure to cdk deploy
all of these automatically created Stacks
before you can deploy your main Stack (the one containing your Pipeline).
Use the cdk ls
command to see all of the Stacks comprising your CDK application.
Example:
$ cdk ls
MyMainStack
aws-cdk-codepipeline-cross-region-scaffolding-us-west-1
$ cdk deploy aws-cdk-codepipeline-cross-region-scaffolding-us-west-1
# output of cdk deploy here...
$ cdk deploy MyMainStack
See the AWS docs here for more information on cross-region CodePipelines.
Events
Using a pipeline as an event target
A pipeline can be used as a target for a CloudWatch event rule:
// kick off the pipeline every day
const rule = new EventRule(this, 'Daily', { scheduleExpression: 'rate(1 day)' });
rule.addTarget(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:
myPipeline.onStateChange('MyPipelineStateChage', target);
myStage.onStateChange('MyStageStateChange', target);
myAction.onStateChange('MyActioStateChange', target);
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for aws-cdk.aws-codepipeline-0.29.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbf978be635ce1512218adc4b0e522ae3bb316efe8727076c6412244c4502902 |
|
MD5 | 4cf1f88645403e6e78dc5e658265ff78 |
|
BLAKE2b-256 | 866f6a949c0cb53258f9d9dca5ea2b5324bd258788162fd167d2b9346054d5d9 |
Hashes for aws_cdk.aws_codepipeline-0.29.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 191356ab5066661b15420ddca1125a635aab9926a9ae68ea11bc36966160a453 |
|
MD5 | 9ecb179536c3d3d344ae42043d33a185 |
|
BLAKE2b-256 | ca5eff91b9d3ac8eb699ed7e58a0f69c48d189e6da6a14034b285ac099b95f4c |