Skip to content

Commit

Permalink
feat: option to configure partition with env var (#895)
Browse files Browse the repository at this point in the history
Adds support for deployment to aws-cn partition by checking an optional environemt variable, `CDK_AWS_PARTITION`. The partition is currently not available to the pipeline in the `jobForDeploy`, adding the environment variable is a non-breaking change to get the pipeline to deploy to aws-cn.

This has been verified with stacks and nested stacks in multiple stages in aws-cn.

Fixes #820
  • Loading branch information
mbergkvist authored Mar 19, 2024
1 parent 1c87348 commit 678f05e
Show file tree
Hide file tree
Showing 9 changed files with 3,267 additions and 2 deletions.
14 changes: 14 additions & 0 deletions API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Workflows.
- [Manual Approval Step](#manual-approval-step)
- [Pipeline YAML Comments](#pipeline-yaml-comments)
- [Common Configuration for Docker Asset Publishing Steps](#common-configuration-for-docker-asset-publishing)
- [AWS China partition support](#aws-china-partition-support)
- [Tutorial](#tutorial)
- [Not supported yet](#not-supported-yet)
- [Contributing](#contributing)
Expand Down Expand Up @@ -644,6 +645,19 @@ const pipeline = new GitHubWorkflow(app, 'Pipeline', {
app.synth();
```

## AWS China partition support

The `CDK_AWS_PARTITION` environment variable can be used to specify the AWS partition for the pipeline.
If it's specified to `aws-cn`, the assets generated by pipeline will reference the resources in
`.amazonaws.com.cn` instead of `.amazonaws.com`.

If `CDK_AWS_PARTITION` environment variable is not specified, the default behaviour for the pipeline is
to use the `aws` partition.

It is not possible to have a pipeline that deploys to both `aws` and `aws-cn` partitions.
If you need to deploy to both partitions, you will need to create two separate pipelines.
The stages and stacks can be shared between the two pipelines.

## Tutorial

You can find an example usage in [test/example-app.ts](./test/example-app.ts)
Expand Down
8 changes: 6 additions & 2 deletions src/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,10 +602,11 @@ export class GitHubWorkflow extends PipelineBase {
}

const resolve = (s: string): string => {
const partition = process.env.CDK_AWS_PARTITION ?? 'aws';
return EnvironmentPlaceholders.replace(s, {
accountId: account,
region: region,
partition: 'aws',
partition: partition,
});
};

Expand All @@ -614,7 +615,10 @@ export class GitHubWorkflow extends PipelineBase {
if (this.assetHashMap[hash] === undefined) {
throw new Error(`Template asset hash ${hash} not found.`);
}
return template.replace(hash, `\${{ needs.${this.assetHashMap[hash]}.outputs.${ASSET_HASH_NAME} }}`);
const updated_template = template.replace(hash, `\${{ needs.${this.assetHashMap[hash]}.outputs.${ASSET_HASH_NAME} }}`);
return process.env.CDK_AWS_PARTITION == 'aws-cn'
? updated_template.replace('.amazonaws.com', '.amazonaws.com.cn')
: updated_template;
};

const params: Record<string, any> = {
Expand Down
Loading

0 comments on commit 678f05e

Please sign in to comment.