Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Oct 26, 2021
2 parents 034fa00 + 82de2e2 commit a527d54
Show file tree
Hide file tree
Showing 56 changed files with 2,212 additions and 359 deletions.
5 changes: 4 additions & 1 deletion pack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ HERE

# copy CHANGELOG.md and RELEASE_NOTES.md to dist/ for github releases
cp ${changelog_file} ${distdir}/CHANGELOG.md
cp RELEASE_NOTES.md ${distdir}/RELEASE_NOTES.md
# Release notes are not available for bump candidate builds.
if ! ${BUMP_CANDIDATE:-false}; then
cp RELEASE_NOTES.md ${distdir}/RELEASE_NOTES.md
fi

# defensive: make sure our artifacts don't use the version marker (this means
# that "pack" will always fails when building in a dev environment)
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
"@aws-cdk/assertions-alpha/string-width/**",
"@aws-cdk/assertions-alpha/table",
"@aws-cdk/assertions-alpha/table/**",
"@aws-cdk/aws-amplify-alpha/yaml",
"@aws-cdk/aws-amplify-alpha/yaml/**",
"@aws-cdk/assertions/colors",
"@aws-cdk/assertions/colors/**",
"@aws-cdk/assertions/diff",
Expand All @@ -91,6 +93,8 @@
"@aws-cdk/assertions/string-width/**",
"@aws-cdk/assertions/table",
"@aws-cdk/assertions/table/**",
"@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",
Expand Down
21 changes: 21 additions & 0 deletions packages/@aws-cdk/aws-amplify/NOTICE
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
AWS Cloud Development Kit (AWS CDK)
Copyright 2018-2021 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 <eemeli@gmail.com>

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.

----------------
29 changes: 29 additions & 0 deletions packages/@aws-cdk/aws-amplify/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,32 @@ const amplifyApp = new amplify.App(this, 'MyApp', {
autoBranchDeletion: true, // Automatically disconnect a branch when you delete a branch from your repository
});
```

## Adding custom response headers

Use the `customResponseHeaders` prop to configure custom response headers for an Amplify app:

```ts
const amplifyApp = new amplify.App(stack, 'App', {
sourceCodeProvider: new amplify.GitHubSourceCodeProvider({
owner: '<user>',
repository: '<repo>',
oauthToken: cdk.SecretValue.secretsManager('my-github-token')
}),
customResponseHeaders: [
{
pattern: '*.json',
headers: {
'custom-header-name-1': 'custom-header-value-1',
'custom-header-name-2': 'custom-header-value-2',
},
},
{
pattern: '/path/*',
headers: {
'custom-header-name-1': 'custom-header-value-2',
},
},
],
});
```
37 changes: 37 additions & 0 deletions packages/@aws-cdk/aws-amplify/lib/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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';
Expand Down Expand Up @@ -118,6 +119,16 @@ export interface AppProps {
*/
readonly buildSpec?: codebuild.BuildSpec;


/**
* The custom HTTP response headers for an Amplify app.
*
* @see https://docs.aws.amazon.com/amplify/latest/userguide/custom-headers.html
*
* @default - no custom response headers
*/
readonly customResponseHeaders?: CustomResponseHeader[];

/**
* Custom rewrite/redirect rules for the application
*
Expand Down Expand Up @@ -238,6 +249,7 @@ export class App extends Resource implements IApp, iam.IGrantable {
name: props.appName || this.node.id,
oauthToken: sourceCodeProviderOptions?.oauthToken?.toString(),
repository: sourceCodeProviderOptions?.repository,
customHeaders: props.customResponseHeaders ? renderCustomResponseHeaders(props.customResponseHeaders) : undefined,
});

this.appId = app.attrAppId;
Expand Down Expand Up @@ -486,3 +498,28 @@ export class CustomRule {
this.condition = options.condition;
}
}

/**
* Custom response header of an Amplify App.
*/
export interface CustomResponseHeader {
/**
* These custom headers will be applied to all URL file paths that match this pattern.
*/
readonly pattern: string;

/**
* The map of custom headers to be applied.
*/
readonly headers: { [key: string]: string };
}

function renderCustomResponseHeaders(customHeaders: CustomResponseHeader[]): string {
const modifiedHeaders = customHeaders.map(customHeader => ({
...customHeader,
headers: Object.entries(customHeader.headers).map(([key, value]) => ({ key, value })),
}));

const customHeadersObject = { customHeaders: modifiedHeaders };
return YAML.stringify(customHeadersObject);
}
9 changes: 7 additions & 2 deletions packages/@aws-cdk/aws-amplify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@
"@aws-cdk/cdk-integ-tools": "0.0.0",
"@aws-cdk/cfn2ts": "0.0.0",
"@aws-cdk/pkglint": "0.0.0",
"@types/jest": "^26.0.24"
"@types/jest": "^26.0.24",
"@types/yaml": "1.9.6"
},
"dependencies": {
"@aws-cdk/aws-codebuild": "0.0.0",
Expand All @@ -88,8 +89,12 @@
"@aws-cdk/aws-kms": "0.0.0",
"@aws-cdk/aws-secretsmanager": "0.0.0",
"@aws-cdk/core": "0.0.0",
"constructs": "^3.3.69"
"constructs": "^3.3.69",
"yaml": "1.10.2"
},
"bundledDependencies": [
"yaml"
],
"peerDependencies": {
"@aws-cdk/aws-codebuild": "0.0.0",
"@aws-cdk/aws-codecommit": "0.0.0",
Expand Down
31 changes: 31 additions & 0 deletions packages/@aws-cdk/aws-amplify/test/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,34 @@ test('with auto branch deletion', () => {
EnableBranchAutoDeletion: true,
});
});

test('with custom headers', () => {
// WHEN
new amplify.App(stack, 'App', {
sourceCodeProvider: new amplify.GitHubSourceCodeProvider({
owner: 'aws',
repository: 'aws-cdk',
oauthToken: SecretValue.plainText('secret'),
}),
customResponseHeaders: [
{
pattern: '*.json',
headers: {
'custom-header-name-1': 'custom-header-value-1',
'custom-header-name-2': 'custom-header-value-2',
},
},
{
pattern: '/path/*',
headers: {
'custom-header-name-1': 'custom-header-value-2',
},
},
],
});

// 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',
});
});
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-amplify/test/integ.app.expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
},
"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",
"CustomRules": [
{
"Source": "/source",
Expand Down
15 changes: 15 additions & 0 deletions packages/@aws-cdk/aws-amplify/test/integ.app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@ class TestStack extends Stack {
const amplifyApp = new amplify.App(this, 'App', {
basicAuth: amplify.BasicAuth.fromGeneratedPassword('aws'),
autoBranchCreation: {},
customResponseHeaders: [
{
pattern: '*.json',
headers: {
'custom-header-name-1': 'custom-header-value-1',
'custom-header-name-2': 'custom-header-value-2',
},
},
{
pattern: '/path/*',
headers: {
'custom-header-name-1': 'custom-header-value-2',
},
},
],
});

amplifyApp.addCustomRule({
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-ec2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ By default, a new security group is created and logging is enabled. Moreover, a
authorize all users to the VPC CIDR is created.

To customize authorization rules, set the `authorizeAllUsersToVpcCidr` prop to `false`
and use `addaddAuthorizationRule()`:
and use `addAuthorizationRule()`:

```ts fixture=client-vpn
const endpoint = vpc.addClientVpnEndpoint('Endpoint', {
Expand Down Expand Up @@ -1110,6 +1110,7 @@ const instance = new ec2.Instance(this, 'Instance', {
const localPath = instance.userData.addS3DownloadCommand({
bucket:asset.bucket,
bucketKey:asset.s3ObjectKey,
region: 'us-east-1', // Optional
});
instance.userData.addExecuteFileCommand({
filePath:localPath,
Expand Down
14 changes: 14 additions & 0 deletions packages/@aws-cdk/aws-ec2/lib/instance-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,20 @@ export enum InstanceClass {
*/
X1E = 'x1e',

/**
* Memory-intensive instances, 2nd generation with Graviton2 processors
*
* This instance type can be used only in RDS. It is not supported in EC2.
*/
MEMORY_INTENSIVE_2_GRAVITON2 = 'x2g',

/**
* Memory-intensive instances, 2nd generation with Graviton2 processors
*
* This instance type can be used only in RDS. It is not supported in EC2.
*/
X2G = 'x2g',

/**
* Memory-intensive instances, 2nd generation with Graviton2 processors and local NVME drive
*/
Expand Down
10 changes: 8 additions & 2 deletions packages/@aws-cdk/aws-ec2/lib/user-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ export interface S3DownloadOptions {
*/
readonly localFile?: string;

/**
* The region of the S3 Bucket (needed for access via VPC Gateway)
* @default none
*/
readonly region?: string

}

/**
Expand Down Expand Up @@ -156,7 +162,7 @@ class LinuxUserData extends UserData {
const localPath = ( params.localFile && params.localFile.length !== 0 ) ? params.localFile : `/tmp/${ params.bucketKey }`;
this.addCommands(
`mkdir -p $(dirname '${localPath}')`,
`aws s3 cp '${s3Path}' '${localPath}'`,
`aws s3 cp '${s3Path}' '${localPath}'` + (params.region !== undefined ? ` --region ${params.region}` : ''),
);

return localPath;
Expand Down Expand Up @@ -215,7 +221,7 @@ class WindowsUserData extends UserData {
const localPath = ( params.localFile && params.localFile.length !== 0 ) ? params.localFile : `C:/temp/${ params.bucketKey }`;
this.addCommands(
`mkdir (Split-Path -Path '${localPath}' ) -ea 0`,
`Read-S3Object -BucketName '${params.bucket.bucketName}' -key '${params.bucketKey}' -file '${localPath}' -ErrorAction Stop`,
`Read-S3Object -BucketName '${params.bucket.bucketName}' -key '${params.bucketKey}' -file '${localPath}' -ErrorAction Stop` + (params.region !== undefined ? ` -Region ${params.region}` : ''),
);
return localPath;
}
Expand Down
Loading

0 comments on commit a527d54

Please sign in to comment.