Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(codepipeline): add example of an ECS Deploy Action #18059

Closed
19 changes: 19 additions & 0 deletions packages/@aws-cdk/aws-codepipeline-actions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,25 @@ Here's an example:

[example ECS pipeline for an application in a separate source code repository](test/integ.pipeline-ecs-separate-source.lit.ts)

#### Deploying to an existing ECS service across account and/or regions

CodePipeline can deploy to an existing ECS service, even across accounts and/or regions.
This requires importing the ECS service in the pipeline stack using the service's full ARN,
which is then used to determine the correct account and region for the ECS Action.
Here's an example:

[example pipeline deploying to an existing ECS service cross account and region](test/integ.ecs-pipeline-cross-region-account-existing.lit.ts)

#### Deploying to a new ECS service across account and/or regions

CodePipeline can also deploy to a new ECS service across accounts and/or regions.
This can be accomplished by using the `Stack.formatArn` method to save the full ARN of the service,
which can then be used to import the ECS service in the pipeline stack,
and the region and account of the ECS Action will be determined from that ARN.
Here's an example:

[example pipeline deploying to a new ECS service cross account and region](test/integ.ecs-pipeline-cross-region-account-new.lit.ts)

### AWS S3 Deployment

To use an S3 Bucket as a deployment target in CodePipeline:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import * as codepipeline from '@aws-cdk/aws-codepipeline';
import * as s3 from '@aws-cdk/aws-s3';
import * as cdk from '@aws-cdk/core';
import { Construct } from 'constructs';
import * as cpactions from '../lib';

/**
* This is our pipeline which has initial actions.
*/
export class EcsServiceCrossRegionAccountPipelineStack extends cdk.Stack {
public artifact: codepipeline.Artifact;
public pipeline: codepipeline.Pipeline;

constructor(scope: Construct, id: string, props: cdk.StackProps) {
super(scope, id, props);

const artifact = new codepipeline.Artifact('Artifact');
this.artifact = artifact;
const bucket = new s3.Bucket(this, 'PipelineBucket', {
versioned: true,
removalPolicy: cdk.RemovalPolicy.DESTROY,
});
const source = new cpactions.S3SourceAction({
actionName: 'Source',
output: artifact,
bucket,
bucketKey: 'key',
});
this.pipeline = new codepipeline.Pipeline(this, 'Pipeline', {
stages: [
{
stageName: 'Source',
actions: [source],
},
],
});

}
}
Loading