-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cloudfront): Distribution does not add edgelambda trust policy (#…
…10006) The stable `CloudFrontWebDistribution` construct automatically adds the 'edgelambda.amazonaws.com' trust policy to the Lambda execution role when adding a Lambda@Edge function to the distribution. The newer `Distribution` construct was missing this functionality. Also added an integ test to validate the Lambda@Edge functions can actually be deployed. fixes #9998 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
4 changed files
with
181 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
packages/@aws-cdk/aws-cloudfront/test/integ.distribution-lambda.expected.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
{ | ||
"Resources": { | ||
"LambdaServiceRoleA8ED4D3B": { | ||
"Type": "AWS::IAM::Role", | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Statement": [ | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "lambda.amazonaws.com" | ||
} | ||
}, | ||
{ | ||
"Action": "sts:AssumeRole", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "edgelambda.amazonaws.com" | ||
} | ||
} | ||
], | ||
"Version": "2012-10-17" | ||
}, | ||
"ManagedPolicyArns": [ | ||
{ | ||
"Fn::Join": [ | ||
"", | ||
[ | ||
"arn:", | ||
{ | ||
"Ref": "AWS::Partition" | ||
}, | ||
":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" | ||
] | ||
] | ||
} | ||
] | ||
} | ||
}, | ||
"LambdaD247545B": { | ||
"Type": "AWS::Lambda::Function", | ||
"Properties": { | ||
"Code": { | ||
"ZipFile": "foo" | ||
}, | ||
"Handler": "index.handler", | ||
"Role": { | ||
"Fn::GetAtt": [ | ||
"LambdaServiceRoleA8ED4D3B", | ||
"Arn" | ||
] | ||
}, | ||
"Runtime": "nodejs10.x" | ||
}, | ||
"DependsOn": [ | ||
"LambdaServiceRoleA8ED4D3B" | ||
] | ||
}, | ||
"LambdaCurrentVersionDF706F6A97fb843e9bd06fcd2bb15eeace80e13e": { | ||
"Type": "AWS::Lambda::Version", | ||
"Properties": { | ||
"FunctionName": { | ||
"Ref": "LambdaD247545B" | ||
} | ||
} | ||
}, | ||
"DistB3B78991": { | ||
"Type": "AWS::CloudFront::Distribution", | ||
"Properties": { | ||
"DistributionConfig": { | ||
"DefaultCacheBehavior": { | ||
"ForwardedValues": { | ||
"QueryString": false | ||
}, | ||
"LambdaFunctionAssociations": [ | ||
{ | ||
"EventType": "origin-request", | ||
"LambdaFunctionARN": { | ||
"Ref": "LambdaCurrentVersionDF706F6A97fb843e9bd06fcd2bb15eeace80e13e" | ||
} | ||
} | ||
], | ||
"TargetOriginId": "integdistributionlambdaDistOrigin133A13098", | ||
"ViewerProtocolPolicy": "allow-all" | ||
}, | ||
"Enabled": true, | ||
"HttpVersion": "http2", | ||
"IPV6Enabled": true, | ||
"Origins": [ | ||
{ | ||
"CustomOriginConfig": { | ||
"OriginProtocolPolicy": "https-only" | ||
}, | ||
"DomainName": "www.example.com", | ||
"Id": "integdistributionlambdaDistOrigin133A13098" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/@aws-cdk/aws-cloudfront/test/integ.distribution-lambda.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import * as lambda from '@aws-cdk/aws-lambda'; | ||
import * as cdk from '@aws-cdk/core'; | ||
import * as cloudfront from '../lib'; | ||
import { TestOrigin } from './test-origin'; | ||
|
||
const app = new cdk.App(); | ||
const stack = new cdk.Stack(app, 'integ-distribution-lambda', { env: { region: 'us-east-1' } }); | ||
|
||
const lambdaFunction = new lambda.Function(stack, 'Lambda', { | ||
code: lambda.Code.fromInline('foo'), | ||
handler: 'index.handler', | ||
runtime: lambda.Runtime.NODEJS_10_X, | ||
}); | ||
|
||
new cloudfront.Distribution(stack, 'Dist', { | ||
defaultBehavior: { | ||
origin: new TestOrigin('www.example.com'), | ||
edgeLambdas: [{ | ||
functionVersion: lambdaFunction.currentVersion, | ||
eventType: cloudfront.LambdaEdgeEventType.ORIGIN_REQUEST, | ||
}], | ||
}, | ||
}); | ||
|
||
app.synth(); |