diff --git a/package.json b/package.json index c6e7cb3182aff..b100e63437b16 100644 --- a/package.json +++ b/package.json @@ -80,12 +80,8 @@ "@aws-cdk/assertions-alpha/fs-extra/**", "@aws-cdk/assertions/fs-extra", "@aws-cdk/assertions/fs-extra/**", - "@aws-cdk/aws-amplify-alpha/yaml", - "@aws-cdk/aws-amplify-alpha/yaml/**", "@aws-cdk/aws-iot-actions-alpha/case", "@aws-cdk/aws-iot-actions-alpha/case/**", - "@aws-cdk/aws-amplify/yaml", - "@aws-cdk/aws-amplify/yaml/**", "@aws-cdk/aws-codebuild/yaml", "@aws-cdk/aws-codebuild/yaml/**", "@aws-cdk/aws-codepipeline-actions/case", diff --git a/packages/@aws-cdk/aws-amplify/NOTICE b/packages/@aws-cdk/aws-amplify/NOTICE index ee9b8119d893f..1b7adbb891265 100644 --- a/packages/@aws-cdk/aws-amplify/NOTICE +++ b/packages/@aws-cdk/aws-amplify/NOTICE @@ -1,23 +1,2 @@ AWS Cloud Development Kit (AWS CDK) Copyright 2018-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. - -------------------------------------------------------------------------------- - -The AWS CDK includes the following third-party software/licensing: - -** yaml - https://www.npmjs.com/package/yaml -Copyright 2018 Eemeli Aro - -Permission to use, copy, modify, and/or distribute this software for any purpose -with or without fee is hereby granted, provided that the above copyright notice -and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH -REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS -OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER -TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF -THIS SOFTWARE. - ----------------- diff --git a/packages/@aws-cdk/aws-amplify/lib/app.ts b/packages/@aws-cdk/aws-amplify/lib/app.ts index 9006d75ec5563..387e89110568b 100644 --- a/packages/@aws-cdk/aws-amplify/lib/app.ts +++ b/packages/@aws-cdk/aws-amplify/lib/app.ts @@ -2,7 +2,6 @@ import * as codebuild from '@aws-cdk/aws-codebuild'; import * as iam from '@aws-cdk/aws-iam'; import { IResource, Lazy, Resource, SecretValue } from '@aws-cdk/core'; import { Construct } from 'constructs'; -import * as YAML from 'yaml'; import { CfnApp } from './amplify.generated'; import { BasicAuth } from './basic-auth'; import { Branch, BranchOptions } from './branch'; @@ -515,11 +514,18 @@ export interface CustomResponseHeader { } function renderCustomResponseHeaders(customHeaders: CustomResponseHeader[]): string { - const modifiedHeaders = customHeaders.map(customHeader => ({ - ...customHeader, - headers: Object.entries(customHeader.headers).map(([key, value]) => ({ key, value })), - })); + const yaml = [ + 'customHeaders:', + ]; + + for (const customHeader of customHeaders) { + yaml.push(` - pattern: "${customHeader.pattern}"`); + yaml.push(' headers:'); + for (const [key, value] of Object.entries(customHeader.headers)) { + yaml.push(` - key: "${key}"`); + yaml.push(` value: "${value}"`); + } + } - const customHeadersObject = { customHeaders: modifiedHeaders }; - return YAML.stringify(customHeadersObject); + return `${yaml.join('\n')}\n`; } diff --git a/packages/@aws-cdk/aws-amplify/package.json b/packages/@aws-cdk/aws-amplify/package.json index eb02bfe5872b3..d94f5b09d8351 100644 --- a/packages/@aws-cdk/aws-amplify/package.json +++ b/packages/@aws-cdk/aws-amplify/package.json @@ -87,7 +87,6 @@ "@aws-cdk/cfn2ts": "0.0.0", "@aws-cdk/pkglint": "0.0.0", "@types/jest": "^27.5.0", - "@types/yaml": "1.9.6", "aws-sdk": "^2.848.0" }, "dependencies": { @@ -101,12 +100,8 @@ "@aws-cdk/aws-secretsmanager": "0.0.0", "@aws-cdk/core": "0.0.0", "@aws-cdk/custom-resources": "0.0.0", - "constructs": "^3.3.69", - "yaml": "1.10.2" + "constructs": "^3.3.69" }, - "bundledDependencies": [ - "yaml" - ], "peerDependencies": { "@aws-cdk/aws-codebuild": "0.0.0", "@aws-cdk/aws-codecommit": "0.0.0", diff --git a/packages/@aws-cdk/aws-amplify/test/app.integ.snapshot/cdk-amplify-app.template.json b/packages/@aws-cdk/aws-amplify/test/app.integ.snapshot/cdk-amplify-app.template.json index e1cca2efc837c..de3117a0134f0 100644 --- a/packages/@aws-cdk/aws-amplify/test/app.integ.snapshot/cdk-amplify-app.template.json +++ b/packages/@aws-cdk/aws-amplify/test/app.integ.snapshot/cdk-amplify-app.template.json @@ -56,7 +56,18 @@ }, "Username": "aws" }, - "CustomHeaders": "customHeaders:\n - pattern: \"*.json\"\n headers:\n - key: custom-header-name-1\n value: custom-header-value-1\n - key: custom-header-name-2\n value: custom-header-value-2\n - pattern: /path/*\n headers:\n - key: custom-header-name-1\n value: custom-header-value-2\n", + "CustomHeaders": { + "Fn::Join": [ + "", + [ + "customHeaders:\n - pattern: \"*.json\"\n headers:\n - key: \"custom-header-name-1\"\n value: \"custom-header-value-1\"\n - key: \"custom-header-name-2\"\n value: \"custom-header-value-2\"\n - pattern: \"/path/*\"\n headers:\n - key: \"custom-header-name-1\"\n value: \"custom-header-value-2\"\n - key: \"x-aws-url-suffix\"\n value: \"this-is-the-suffix-", + { + "Ref": "AWS::URLSuffix" + }, + "\"\n" + ] + ] + }, "CustomRules": [ { "Source": "/source", diff --git a/packages/@aws-cdk/aws-amplify/test/app.integ.snapshot/cdk.out b/packages/@aws-cdk/aws-amplify/test/app.integ.snapshot/cdk.out index 90bef2e09ad39..ccdfc1ff96a9d 100644 --- a/packages/@aws-cdk/aws-amplify/test/app.integ.snapshot/cdk.out +++ b/packages/@aws-cdk/aws-amplify/test/app.integ.snapshot/cdk.out @@ -1 +1 @@ -{"version":"17.0.0"} \ No newline at end of file +{"version":"19.0.0"} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-amplify/test/app.integ.snapshot/integ.json b/packages/@aws-cdk/aws-amplify/test/app.integ.snapshot/integ.json index cca9d18d99d00..93176aef2bf66 100644 --- a/packages/@aws-cdk/aws-amplify/test/app.integ.snapshot/integ.json +++ b/packages/@aws-cdk/aws-amplify/test/app.integ.snapshot/integ.json @@ -1,7 +1,7 @@ { - "version": "18.0.0", + "version": "19.0.0", "testCases": { - "aws-amplify/test/integ.app": { + "integ.app": { "stacks": [ "cdk-amplify-app" ], diff --git a/packages/@aws-cdk/aws-amplify/test/app.integ.snapshot/manifest.json b/packages/@aws-cdk/aws-amplify/test/app.integ.snapshot/manifest.json index 65552a1fcf8ed..87a66ac86ab92 100644 --- a/packages/@aws-cdk/aws-amplify/test/app.integ.snapshot/manifest.json +++ b/packages/@aws-cdk/aws-amplify/test/app.integ.snapshot/manifest.json @@ -1,5 +1,5 @@ { - "version": "17.0.0", + "version": "19.0.0", "artifacts": { "Tree": { "type": "cdk:tree", diff --git a/packages/@aws-cdk/aws-amplify/test/app.integ.snapshot/tree.json b/packages/@aws-cdk/aws-amplify/test/app.integ.snapshot/tree.json index 9512a839b4c35..1704713d2033f 100644 --- a/packages/@aws-cdk/aws-amplify/test/app.integ.snapshot/tree.json +++ b/packages/@aws-cdk/aws-amplify/test/app.integ.snapshot/tree.json @@ -113,7 +113,18 @@ ] } }, - "customHeaders": "customHeaders:\n - pattern: \"*.json\"\n headers:\n - key: custom-header-name-1\n value: custom-header-value-1\n - key: custom-header-name-2\n value: custom-header-value-2\n - pattern: /path/*\n headers:\n - key: custom-header-name-1\n value: custom-header-value-2\n", + "customHeaders": { + "Fn::Join": [ + "", + [ + "customHeaders:\n - pattern: \"*.json\"\n headers:\n - key: \"custom-header-name-1\"\n value: \"custom-header-value-1\"\n - key: \"custom-header-name-2\"\n value: \"custom-header-value-2\"\n - pattern: \"/path/*\"\n headers:\n - key: \"custom-header-name-1\"\n value: \"custom-header-value-2\"\n - key: \"x-aws-url-suffix\"\n value: \"this-is-the-suffix-", + { + "Ref": "AWS::URLSuffix" + }, + "\"\n" + ] + ] + }, "customRules": [ { "source": "/source", diff --git a/packages/@aws-cdk/aws-amplify/test/app.test.ts b/packages/@aws-cdk/aws-amplify/test/app.test.ts index bdb59e43df1fa..d778ce133b337 100644 --- a/packages/@aws-cdk/aws-amplify/test/app.test.ts +++ b/packages/@aws-cdk/aws-amplify/test/app.test.ts @@ -417,11 +417,28 @@ test('with custom headers', () => { 'custom-header-name-1': 'custom-header-value-2', }, }, + { + pattern: '/with-tokens/*', + headers: { + 'x-custom': `${'hello'.repeat(10)}${Stack.of(stack).urlSuffix} `, + }, + }, ], }); // THEN Template.fromStack(stack).hasResourceProperties('AWS::Amplify::App', { - CustomHeaders: 'customHeaders:\n - pattern: "*.json"\n headers:\n - key: custom-header-name-1\n value: custom-header-value-1\n - key: custom-header-name-2\n value: custom-header-value-2\n - pattern: /path/*\n headers:\n - key: custom-header-name-1\n value: custom-header-value-2\n', + CustomHeaders: { + 'Fn::Join': [ + '', + [ + 'customHeaders:\n - pattern: "*.json"\n headers:\n - key: "custom-header-name-1"\n value: "custom-header-value-1"\n - key: "custom-header-name-2"\n value: "custom-header-value-2"\n - pattern: "/path/*"\n headers:\n - key: "custom-header-name-1"\n value: "custom-header-value-2"\n - pattern: "/with-tokens/*"\n headers:\n - key: "x-custom"\n value: "hellohellohellohellohellohellohellohellohellohello', + { + Ref: 'AWS::URLSuffix', + }, + ' "\n', + ], + ], + }, }); }); diff --git a/packages/@aws-cdk/aws-amplify/test/integ.app.ts b/packages/@aws-cdk/aws-amplify/test/integ.app.ts index accdaed6840bf..b9c6f0e0872f2 100644 --- a/packages/@aws-cdk/aws-amplify/test/integ.app.ts +++ b/packages/@aws-cdk/aws-amplify/test/integ.app.ts @@ -21,6 +21,7 @@ class TestStack extends Stack { pattern: '/path/*', headers: { 'custom-header-name-1': 'custom-header-value-2', + 'x-aws-url-suffix': `this-is-the-suffix-${Stack.of(this).urlSuffix}`, }, }, ],