From 673f91425c033bd1011d707e30ba557c109d2236 Mon Sep 17 00:00:00 2001 From: Julian Michel Date: Wed, 2 Feb 2022 01:47:41 +0100 Subject: [PATCH] feat(amplify): support performance mode in Branch (#18598) Add support for [performance mode](https://docs.aws.amazon.com/amplify/latest/userguide/ttl.html#Performance-mode ) in Amplify branches. Performance mode optimizes for faster hosting performance by keeping content cached at the edge for a longer interval. Closes #18557. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/@aws-cdk/aws-amplify/README.md | 4 +++- packages/@aws-cdk/aws-amplify/lib/branch.ts | 12 ++++++++++++ packages/@aws-cdk/aws-amplify/test/branch.test.ts | 12 ++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-amplify/README.md b/packages/@aws-cdk/aws-amplify/README.md index 04d9f0d95bf08..fffaf2ac97bcf 100644 --- a/packages/@aws-cdk/aws-amplify/README.md +++ b/packages/@aws-cdk/aws-amplify/README.md @@ -97,7 +97,9 @@ Add branches: declare const amplifyApp: amplify.App; const master = amplifyApp.addBranch('master'); // `id` will be used as repo branch name -const dev = amplifyApp.addBranch('dev'); +const dev = amplifyApp.addBranch('dev', { + performanceMode: true, // optional, enables performance mode +}); dev.addEnvironment('STAGE', 'dev'); ``` diff --git a/packages/@aws-cdk/aws-amplify/lib/branch.ts b/packages/@aws-cdk/aws-amplify/lib/branch.ts index 3298f7a246056..40c1bdb3d0671 100644 --- a/packages/@aws-cdk/aws-amplify/lib/branch.ts +++ b/packages/@aws-cdk/aws-amplify/lib/branch.ts @@ -114,6 +114,17 @@ export interface BranchOptions { * @default - no asset */ readonly asset?: Asset + + /** + * Enables performance mode for the branch. + * + * Performance mode optimizes for faster hosting performance by keeping content cached at the edge + * for a longer interval. When performance mode is enabled, hosting configuration or code changes + * can take up to 10 minutes to roll out. + * + * @default false + */ + readonly performanceMode?: boolean; } /** @@ -168,6 +179,7 @@ export class Branch extends Resource implements IBranch { environmentVariables: Lazy.any({ produce: () => renderEnvironmentVariables(this.environmentVariables) }, { omitEmptyArray: true }), pullRequestEnvironmentName: props.pullRequestEnvironmentName, stage: props.stage, + enablePerformanceMode: props.performanceMode, }); this.arn = branch.attrArn; diff --git a/packages/@aws-cdk/aws-amplify/test/branch.test.ts b/packages/@aws-cdk/aws-amplify/test/branch.test.ts index ba8e517205beb..888a92117fb9c 100644 --- a/packages/@aws-cdk/aws-amplify/test/branch.test.ts +++ b/packages/@aws-cdk/aws-amplify/test/branch.test.ts @@ -162,3 +162,15 @@ test('with asset deployment', () => { }, }); }); + +test('with performance mode', () => { + // WHEN + app.addBranch('dev', { + performanceMode: true, + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::Amplify::Branch', { + EnablePerformanceMode: true, + }); +});