Skip to content

Commit

Permalink
feat(amplify): support performance mode in Branch (#18598)
Browse files Browse the repository at this point in the history
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*
  • Loading branch information
jumic authored Feb 2, 2022
1 parent 73a889e commit bdeb8eb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/@aws-cdk/aws-amplify/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');
```

Expand Down
12 changes: 12 additions & 0 deletions packages/@aws-cdk/aws-amplify/lib/branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions packages/@aws-cdk/aws-amplify/test/branch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
});

0 comments on commit bdeb8eb

Please sign in to comment.