From 2bd1c4fc7a650a4c67d6c0df4384967c10d848ba Mon Sep 17 00:00:00 2001 From: Kevin Old Date: Wed, 8 Feb 2023 16:35:18 -0600 Subject: [PATCH] feat(amplify): Add platform property to Amplify AppProps Adds AppPlatforms enum for WEB, WEB_COMPUTE or WEB_DYNAMIC Adds platform property to AppProps Passes platform property to declared Amplify app fixes #24076 --- packages/@aws-cdk/aws-amplify/lib/app.ts | 20 +++++++++++++++++++ .../@aws-cdk/aws-amplify/test/app.test.ts | 18 +++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/packages/@aws-cdk/aws-amplify/lib/app.ts b/packages/@aws-cdk/aws-amplify/lib/app.ts index 387e89110568b..25cf388c82b5d 100644 --- a/packages/@aws-cdk/aws-amplify/lib/app.ts +++ b/packages/@aws-cdk/aws-amplify/lib/app.ts @@ -66,6 +66,15 @@ export interface ISourceCodeProvider { bind(app: App): SourceCodeProviderConfig; } +/** + * The platform for the Amplify app. + */ +export enum AppPlatforms { + WEB = 'WEB', + WEB_COMPUTE = 'WEB_COMPUTE', + WEB_DYNAMIC = 'WEB_DYNAMIC', +} + /** * Properties for an App */ @@ -159,6 +168,16 @@ export interface AppProps { * @default - a new role is created */ readonly role?: iam.IRole; + + /** + * The platform for the Amplify app. + * For a static app, set the platform type to WEB. + * For a dynamic server-side rendered (SSR) app, set the platform type to WEB_COMPUTE. + * For an app requiring Amplify Hosting's original SSR support only, set the platform type to WEB_DYNAMIC. + * + * @default WEB + */ + readonly platform?: AppPlatforms; } /** @@ -249,6 +268,7 @@ export class App extends Resource implements IApp, iam.IGrantable { oauthToken: sourceCodeProviderOptions?.oauthToken?.unsafeUnwrap(), // Safe usage repository: sourceCodeProviderOptions?.repository, customHeaders: props.customResponseHeaders ? renderCustomResponseHeaders(props.customResponseHeaders) : undefined, + platform: props.platform, }); this.appId = app.attrAppId; diff --git a/packages/@aws-cdk/aws-amplify/test/app.test.ts b/packages/@aws-cdk/aws-amplify/test/app.test.ts index d778ce133b337..7df12b990dab0 100644 --- a/packages/@aws-cdk/aws-amplify/test/app.test.ts +++ b/packages/@aws-cdk/aws-amplify/test/app.test.ts @@ -3,6 +3,7 @@ import * as codebuild from '@aws-cdk/aws-codebuild'; import * as codecommit from '@aws-cdk/aws-codecommit'; import { SecretValue, Stack } from '@aws-cdk/core'; import * as amplify from '../lib'; +import { AppPlatforms } from '../lib'; let stack: Stack; beforeEach(() => { @@ -442,3 +443,20 @@ test('with custom headers', () => { }, }); }); + +test('with WEB_COMPUTE platform', () => { + // WHEN + new amplify.App(stack, 'App', { + sourceCodeProvider: new amplify.GitHubSourceCodeProvider({ + owner: 'aws', + repository: 'aws-cdk', + oauthToken: SecretValue.unsafePlainText('secret'), + }), + platform: AppPlatforms.WEB_COMPUTE + }); + + // THEN + Template.fromStack(stack).hasResourceProperties('AWS::Amplify::App', { + Platform: "WEB_COMPUTE", + }); +}); \ No newline at end of file