Skip to content

Commit 0c84ab2

Browse files
authored
Merge branch 'master' into query
2 parents 0fa73d3 + ba51ea3 commit 0c84ab2

29 files changed

+956
-191
lines changed

CHANGELOG.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
## [1.61.1](https://github.com/aws/aws-cdk/compare/v1.61.0...v1.61.1) (2020-08-28)
6+
7+
8+
### Bug Fixes
9+
10+
* **cli:** unable to upgrade new style bootstrap to version ([#10030](https://github.com/aws/aws-cdk/issues/10030)) ([8d3e422](https://github.com/aws/aws-cdk/commit/8d3e422809c29da926bae878276619a59ae82ecb)), closes [#10016](https://github.com/aws/aws-cdk/issues/10016)
11+
512
## [1.61.0](https://github.com/aws/aws-cdk/compare/v1.60.0...v1.61.0) (2020-08-27)
613

714

@@ -39,7 +46,7 @@ All notable changes to this project will be documented in this file. See [standa
3946
### ⚠ BREAKING CHANGES TO EXPERIMENTAL FEATURES
4047

4148
* **cloudfront:** Distribution: `.domains` must be specified if `certificate` is provided.
42-
* **appsync:** **appsync.addXxxDataSource** `name` and `description` props are now optional and in an `DataSourceOptions` interface.
49+
* **appsync:** **appsync.addXxxDataSource** `name` and `description` props are now optional and in an `DataSourceOptions` interface.
4350
- **appsync**: the props `name` and `description` in `addXxxDataSource` have been moved into new props `options` of type `DataSourceOptions`
4451
- **appsync**: `DataSourceOptions.name` defaults to id
4552
- **appsync**: `DataSourceOptions.description` defaults to undefined

lerna.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
"tools/*"
1111
],
1212
"rejectCycles": "true",
13-
"version": "1.61.0"
13+
"version": "1.61.1"
1414
}

packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ export class GraphQLApi extends GraphqlApiBase {
533533
userPoolId: config.userPool.userPoolId,
534534
awsRegion: config.userPool.stack.region,
535535
appIdClientRegex: config.appIdClientRegex,
536-
defaultAction: config.defaultAction,
536+
defaultAction: config.defaultAction || UserPoolDefaultAction.ALLOW,
537537
};
538538
}
539539

packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ describe('AppSync User Pool Authorization', () => {
250250
AuthenticationType: 'AMAZON_COGNITO_USER_POOLS',
251251
UserPoolConfig: {
252252
AwsRegion: { Ref: 'AWS::Region' },
253+
DefaultAction: 'ALLOW',
253254
UserPoolId: { Ref: 'pool056F3F7E' },
254255
},
255256
});
@@ -371,6 +372,7 @@ describe('AppSync User Pool Authorization', () => {
371372
AuthenticationType: 'AMAZON_COGNITO_USER_POOLS',
372373
UserPoolConfig: {
373374
AwsRegion: { Ref: 'AWS::Region' },
375+
DefaultAction: 'ALLOW',
374376
UserPoolId: { Ref: 'pool056F3F7E' },
375377
},
376378
AdditionalAuthenticationProviders: [

packages/@aws-cdk/aws-appsync/test/integ.graphql.ts

-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
MappingTemplate,
1010
PrimaryKey,
1111
Schema,
12-
UserPoolDefaultAction,
1312
Values,
1413
} from '../lib';
1514

@@ -42,7 +41,6 @@ const api = new GraphQLApi(stack, 'Api', {
4241
authorizationType: AuthorizationType.USER_POOL,
4342
userPoolConfig: {
4443
userPool,
45-
defaultAction: UserPoolDefaultAction.ALLOW,
4644
},
4745
},
4846
additionalAuthorizationModes: [

packages/@aws-cdk/aws-cloudfront/README.md

+15-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ new cloudfront.Distribution(this, 'myDist', {
8282
});
8383
```
8484

85-
## From an HTTP endpoint
85+
#### From an HTTP endpoint
8686

8787
Origins can also be created from any other HTTP endpoint, given the domain name, and optionally, other origin properties.
8888

@@ -207,6 +207,7 @@ new cloudfront.Distribution(this, 'myDist', {
207207
{
208208
functionVersion: myFunc.currentVersion,
209209
eventType: cloudfront.LambdaEdgeEventType.ORIGIN_REQUEST,
210+
includeBody: true, // Optional - defaults to false
210211
},
211212
],
212213
},
@@ -246,6 +247,18 @@ new cloudfront.Distribution(this, 'myDist', {
246247
});
247248
```
248249

250+
### Importing Distributions
251+
252+
Existing distributions can be imported as well; note that like most imported constructs, an imported distribution cannot be modified.
253+
However, it can be used as a reference for other higher-level constructs.
254+
255+
```ts
256+
const distribution = cloudfront.Distribution.fromDistributionAttributes(scope, 'ImportedDist', {
257+
domainName: 'd111111abcdef8.cloudfront.net',
258+
distributionId: '012345ABCDEF',
259+
});
260+
```
261+
249262
## CloudFrontWebDistribution API - Stable
250263

251264
![cdk-constructs: Stable](https://img.shields.io/badge/cdk--constructs-stable-success.svg?style=for-the-badge)
@@ -305,7 +318,7 @@ Example:
305318

306319
[create a distrubution with an iam certificate example](test/example.iam-cert-alias.lit.ts)
307320

308-
#### Restrictions
321+
### Restrictions
309322

310323
CloudFront supports adding restrictions to your distribution.
311324

packages/@aws-cdk/aws-cloudfront/lib/distribution.ts

+9
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,15 @@ export interface EdgeLambda {
621621

622622
/** The type of event in response to which should the function be invoked. */
623623
readonly eventType: LambdaEdgeEventType;
624+
625+
/**
626+
* Allows a Lambda function to have read access to the body content.
627+
* Only valid for "request" event types (`ORIGIN_REQUEST` or `VIEWER_REQUEST`).
628+
* See https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-include-body-access.html
629+
*
630+
* @default false
631+
*/
632+
readonly includeBody?: boolean;
624633
}
625634

626635
/**

packages/@aws-cdk/aws-cloudfront/lib/private/cache-behavior.ts

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import * as iam from '@aws-cdk/aws-iam';
12
import { CfnDistribution } from '../cloudfront.generated';
2-
import { AddBehaviorOptions, ViewerProtocolPolicy } from '../distribution';
3+
import { AddBehaviorOptions, EdgeLambda, LambdaEdgeEventType, ViewerProtocolPolicy } from '../distribution';
34

45
/**
56
* Properties for specifying custom behaviors for origins.
@@ -24,6 +25,9 @@ export class CacheBehavior {
2425

2526
constructor(originId: string, private readonly props: CacheBehaviorProps) {
2627
this.originId = originId;
28+
29+
this.validateEdgeLambdas(props.edgeLambdas);
30+
this.grantEdgeLambdaFunctionExecutionRole(props.edgeLambdas);
2731
}
2832

2933
/**
@@ -51,8 +55,29 @@ export class CacheBehavior {
5155
? this.props.edgeLambdas.map(edgeLambda => ({
5256
lambdaFunctionArn: edgeLambda.functionVersion.edgeArn,
5357
eventType: edgeLambda.eventType.toString(),
58+
includeBody: edgeLambda.includeBody,
5459
}))
5560
: undefined,
5661
};
5762
}
63+
64+
private validateEdgeLambdas(edgeLambdas?: EdgeLambda[]) {
65+
const includeBodyEventTypes = [LambdaEdgeEventType.ORIGIN_REQUEST, LambdaEdgeEventType.VIEWER_REQUEST];
66+
if (edgeLambdas && edgeLambdas.some(lambda => lambda.includeBody && !includeBodyEventTypes.includes(lambda.eventType))) {
67+
throw new Error('\'includeBody\' can only be true for ORIGIN_REQUEST or VIEWER_REQUEST event types.');
68+
}
69+
}
70+
71+
private grantEdgeLambdaFunctionExecutionRole(edgeLambdas?: EdgeLambda[]) {
72+
if (!edgeLambdas || edgeLambdas.length === 0) { return; }
73+
edgeLambdas.forEach((edgeLambda) => {
74+
const role = edgeLambda.functionVersion.role;
75+
if (role && role instanceof iam.Role && role.assumeRolePolicy) {
76+
role.assumeRolePolicy.addStatements(new iam.PolicyStatement({
77+
actions: ['sts:AssumeRole'],
78+
principals: [new iam.ServicePrincipal('edgelambda.amazonaws.com')],
79+
}));
80+
}
81+
});
82+
}
5883
}

packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts

+55
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,15 @@ export interface LambdaFunctionAssociation {
424424
* A version of the lambda to associate
425425
*/
426426
readonly lambdaFunction: lambda.IVersion;
427+
428+
/**
429+
* Allows a Lambda function to have read access to the body content.
430+
* Only valid for "request" event types (`ORIGIN_REQUEST` or `VIEWER_REQUEST`).
431+
* See https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-include-body-access.html
432+
*
433+
* @default false
434+
*/
435+
readonly includeBody?: boolean;
427436
}
428437

429438
export interface ViewerCertificateOptions {
@@ -628,6 +637,27 @@ interface BehaviorWithOrigin extends Behavior {
628637
readonly targetOriginId: string;
629638
}
630639

640+
/**
641+
* Attributes used to import a Distribution.
642+
*
643+
* @experimental
644+
*/
645+
export interface CloudFrontWebDistributionAttributes {
646+
/**
647+
* The generated domain name of the Distribution, such as d111111abcdef8.cloudfront.net.
648+
*
649+
* @attribute
650+
*/
651+
readonly domainName: string;
652+
653+
/**
654+
* The distribution ID for this distribution.
655+
*
656+
* @attribute
657+
*/
658+
readonly distributionId: string;
659+
}
660+
631661
/**
632662
* Amazon CloudFront is a global content delivery network (CDN) service that securely delivers data, videos,
633663
* applications, and APIs to your viewers with low latency and high transfer speeds.
@@ -659,6 +689,25 @@ interface BehaviorWithOrigin extends Behavior {
659689
* @resource AWS::CloudFront::Distribution
660690
*/
661691
export class CloudFrontWebDistribution extends cdk.Resource implements IDistribution {
692+
693+
/**
694+
* Creates a construct that represents an external (imported) distribution.
695+
*/
696+
public static fromDistributionAttributes(scope: cdk.Construct, id: string, attrs: CloudFrontWebDistributionAttributes): IDistribution {
697+
return new class extends cdk.Resource implements IDistribution {
698+
public readonly domainName: string;
699+
public readonly distributionDomainName: string;
700+
public readonly distributionId: string;
701+
702+
constructor() {
703+
super(scope, id);
704+
this.domainName = attrs.domainName;
705+
this.distributionDomainName = attrs.domainName;
706+
this.distributionId = attrs.distributionId;
707+
}
708+
}();
709+
}
710+
662711
/**
663712
* The logging bucket for this CloudFront distribution.
664713
* If logging is not enabled for this distribution - this property will be undefined.
@@ -892,11 +941,17 @@ export class CloudFrontWebDistribution extends cdk.Resource implements IDistribu
892941
toReturn = Object.assign(toReturn, { pathPattern: input.pathPattern });
893942
}
894943
if (input.lambdaFunctionAssociations) {
944+
const includeBodyEventTypes = [LambdaEdgeEventType.ORIGIN_REQUEST, LambdaEdgeEventType.VIEWER_REQUEST];
945+
if (input.lambdaFunctionAssociations.some(fna => fna.includeBody && !includeBodyEventTypes.includes(fna.eventType))) {
946+
throw new Error('\'includeBody\' can only be true for ORIGIN_REQUEST or VIEWER_REQUEST event types.');
947+
}
948+
895949
toReturn = Object.assign(toReturn, {
896950
lambdaFunctionAssociations: input.lambdaFunctionAssociations
897951
.map(fna => ({
898952
eventType: fna.eventType,
899953
lambdaFunctionArn: fna.lambdaFunction && fna.lambdaFunction.edgeArn,
954+
includeBody: fna.includeBody,
900955
})),
901956
});
902957

packages/@aws-cdk/aws-cloudfront/test/distribution.test.ts

+38
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ describe('with Lambda@Edge functions', () => {
468468
{
469469
functionVersion: lambdaFunction.currentVersion,
470470
eventType: LambdaEdgeEventType.ORIGIN_REQUEST,
471+
includeBody: true,
471472
},
472473
],
473474
},
@@ -479,6 +480,7 @@ describe('with Lambda@Edge functions', () => {
479480
LambdaFunctionAssociations: [
480481
{
481482
EventType: 'origin-request',
483+
IncludeBody: true,
482484
LambdaFunctionARN: {
483485
Ref: 'FunctionCurrentVersion4E2B2261477a5ae8059bbaa7813f752292c0f65e',
484486
},
@@ -489,6 +491,42 @@ describe('with Lambda@Edge functions', () => {
489491
});
490492
});
491493

494+
test('edgelambda.amazonaws.com is added to the trust policy of lambda', () => {
495+
new Distribution(stack, 'MyDist', {
496+
defaultBehavior: {
497+
origin,
498+
edgeLambdas: [
499+
{
500+
functionVersion: lambdaFunction.currentVersion,
501+
eventType: LambdaEdgeEventType.ORIGIN_REQUEST,
502+
},
503+
],
504+
},
505+
});
506+
507+
expect(stack).toHaveResource('AWS::IAM::Role', {
508+
AssumeRolePolicyDocument: {
509+
Statement: [
510+
{
511+
Action: 'sts:AssumeRole',
512+
Effect: 'Allow',
513+
Principal: {
514+
Service: 'lambda.amazonaws.com',
515+
},
516+
},
517+
{
518+
Action: 'sts:AssumeRole',
519+
Effect: 'Allow',
520+
Principal: {
521+
Service: 'edgelambda.amazonaws.com',
522+
},
523+
},
524+
],
525+
Version: '2012-10-17',
526+
},
527+
});
528+
});
529+
492530
test('can add an edge lambdas to additional behaviors', () => {
493531
new Distribution(stack, 'MyDist', {
494532
defaultBehavior: { origin },

0 commit comments

Comments
 (0)