Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cloudfront): support includeBody for Lambda@Edge #10008

Merged
merged 5 commits into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-cloudfront/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ new cloudfront.Distribution(this, 'myDist', {
{
functionVersion: myFunc.currentVersion,
eventType: cloudfront.LambdaEdgeEventType.ORIGIN_REQUEST,
includeBody: true, // Optional - defaults to false
},
],
},
Expand Down
8 changes: 8 additions & 0 deletions packages/@aws-cdk/aws-cloudfront/lib/distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,14 @@ export interface EdgeLambda {

/** The type of event in response to which should the function be invoked. */
readonly eventType: LambdaEdgeEventType;

/**
* Allows a Lambda function to have read access to the body content.
* See https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-include-body-access.html
*
* @default false
*/
readonly includeBody?: boolean;
njlynch marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export class CacheBehavior {
? this.props.edgeLambdas.map(edgeLambda => ({
lambdaFunctionArn: edgeLambda.functionVersion.edgeArn,
eventType: edgeLambda.eventType.toString(),
includeBody: edgeLambda.includeBody,
}))
: undefined,
};
Expand Down
9 changes: 9 additions & 0 deletions packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,14 @@ export interface LambdaFunctionAssociation {
* A version of the lambda to associate
*/
readonly lambdaFunction: lambda.IVersion;

/**
* Allows a Lambda function to have read access to the body content.
* See https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-include-body-access.html
*
* @default false
*/
readonly includeBody?: boolean;
}

export interface ViewerCertificateOptions {
Expand Down Expand Up @@ -897,6 +905,7 @@ export class CloudFrontWebDistribution extends cdk.Resource implements IDistribu
.map(fna => ({
eventType: fna.eventType,
lambdaFunctionArn: fna.lambdaFunction && fna.lambdaFunction.edgeArn,
includeBody: fna.includeBody,
})),
});

Expand Down
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-cloudfront/test/distribution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ describe('with Lambda@Edge functions', () => {
{
functionVersion: lambdaFunction.currentVersion,
eventType: LambdaEdgeEventType.ORIGIN_REQUEST,
includeBody: true,
},
],
},
Expand All @@ -479,6 +480,7 @@ describe('with Lambda@Edge functions', () => {
LambdaFunctionAssociations: [
{
EventType: 'origin-request',
IncludeBody: true,
LambdaFunctionARN: {
Ref: 'FunctionCurrentVersion4E2B2261477a5ae8059bbaa7813f752292c0f65e',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ nodeunitShim({
lambdaFunctionAssociations: [{
eventType: LambdaEdgeEventType.ORIGIN_REQUEST,
lambdaFunction: lambdaFunction.currentVersion,
includeBody: true,
}],
},
],
Expand All @@ -457,6 +458,7 @@ nodeunitShim({
'LambdaFunctionAssociations': [
{
'EventType': 'origin-request',
'IncludeBody': true,
'LambdaFunctionARN': {
'Ref': 'LambdaCurrentVersionDF706F6A97fb843e9bd06fcd2bb15eeace80e13e',
},
Expand Down