-
Notifications
You must be signed in to change notification settings - Fork 4k
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
fix(lambda-nodejs): NodejsFunction construct incompatible with lambda@edge #9562
Changes from 13 commits
625d49b
0bde106
5dcc8d5
3f55a28
7a05847
1ab542b
b538779
9465e60
2ff9840
c1dc747
5455085
006206b
1ce04e1
efd2327
6c9fdc7
b878a9b
deed339
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { expect, haveResource, haveResourceLike } from '@aws-cdk/assert'; | ||
import { ABSENT, expect, haveResource, haveResourceLike } from '@aws-cdk/assert'; | ||
import * as certificatemanager from '@aws-cdk/aws-certificatemanager'; | ||
import * as lambda from '@aws-cdk/aws-lambda'; | ||
import * as s3 from '@aws-cdk/aws-s3'; | ||
|
@@ -426,8 +426,7 @@ nodeunitShim({ | |
const stack = new cdk.Stack(); | ||
const sourceBucket = new s3.Bucket(stack, 'Bucket'); | ||
|
||
const lambdaFunction = new lambda.SingletonFunction(stack, 'Lambda', { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Had to move from a
|
||
uuid: 'xxxx-xxxx-xxxx-xxxx', | ||
const lambdaFunction = new lambda.Function(stack, 'Lambda', { | ||
code: lambda.Code.inline('foo'), | ||
handler: 'index.handler', | ||
runtime: lambda.Runtime.NODEJS_10_X, | ||
|
@@ -444,7 +443,7 @@ nodeunitShim({ | |
isDefaultBehavior: true, | ||
lambdaFunctionAssociations: [{ | ||
eventType: LambdaEdgeEventType.ORIGIN_REQUEST, | ||
lambdaFunction: lambdaFunction.latestVersion, | ||
lambdaFunction: lambdaFunction.addVersion('1'), | ||
}], | ||
}, | ||
], | ||
|
@@ -459,13 +458,7 @@ nodeunitShim({ | |
{ | ||
'EventType': 'origin-request', | ||
'LambdaFunctionARN': { | ||
'Fn::Join': [ | ||
'', | ||
[ | ||
{ 'Fn::GetAtt': ['SingletonLambdaxxxxxxxxxxxxxxxx69D4268A', 'Arn'] }, | ||
':$LATEST', | ||
], | ||
], | ||
'Ref': 'LambdaVersion1BB7548E1', | ||
}, | ||
}, | ||
], | ||
|
@@ -476,6 +469,82 @@ nodeunitShim({ | |
test.done(); | ||
}, | ||
|
||
'associate a lambda with removable env vars'(test: Test) { | ||
const app = new cdk.App(); | ||
const stack = new cdk.Stack(app, 'Stack'); | ||
const sourceBucket = new s3.Bucket(stack, 'Bucket'); | ||
|
||
const lambdaFunction = new lambda.Function(stack, 'Lambda', { | ||
code: lambda.Code.inline('foo'), | ||
handler: 'index.handler', | ||
runtime: lambda.Runtime.NODEJS_10_X, | ||
}); | ||
lambdaFunction.addEnvironment('KEY', 'value', { removeInEdge: true }); | ||
|
||
new CloudFrontWebDistribution(stack, 'AnAmazingWebsiteProbably', { | ||
originConfigs: [ | ||
{ | ||
s3OriginSource: { | ||
s3BucketSource: sourceBucket, | ||
}, | ||
behaviors: [ | ||
{ | ||
isDefaultBehavior: true, | ||
lambdaFunctionAssociations: [{ | ||
eventType: LambdaEdgeEventType.ORIGIN_REQUEST, | ||
lambdaFunction: lambdaFunction.addVersion('1'), | ||
}], | ||
}, | ||
], | ||
}, | ||
], | ||
}); | ||
|
||
expect(stack).to(haveResource('AWS::Lambda::Function', { | ||
Environment: ABSENT, | ||
})); | ||
|
||
test.done(); | ||
}, | ||
|
||
'throws when associating a lambda with incompatible env vars'(test: Test) { | ||
const app = new cdk.App(); | ||
const stack = new cdk.Stack(app, 'Stack'); | ||
const sourceBucket = new s3.Bucket(stack, 'Bucket'); | ||
|
||
const lambdaFunction = new lambda.Function(stack, 'Lambda', { | ||
code: lambda.Code.inline('foo'), | ||
handler: 'index.handler', | ||
runtime: lambda.Runtime.NODEJS_10_X, | ||
environment: { | ||
KEY: 'value', | ||
}, | ||
}); | ||
|
||
new CloudFrontWebDistribution(stack, 'AnAmazingWebsiteProbably', { | ||
originConfigs: [ | ||
{ | ||
s3OriginSource: { | ||
s3BucketSource: sourceBucket, | ||
}, | ||
behaviors: [ | ||
{ | ||
isDefaultBehavior: true, | ||
lambdaFunctionAssociations: [{ | ||
eventType: LambdaEdgeEventType.ORIGIN_REQUEST, | ||
lambdaFunction: lambdaFunction.addVersion('1'), | ||
}], | ||
}, | ||
], | ||
}, | ||
], | ||
}); | ||
|
||
test.throws(() => app.synth(), /KEY/); | ||
|
||
test.done(); | ||
}, | ||
|
||
'distribution has a defaultChild'(test: Test) { | ||
const stack = new cdk.Stack(); | ||
const sourceBucket = new s3.Bucket(stack, 'Bucket'); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
edgeArn
must always be lazily processed. Would be better to move theLazy.stringValue()
block into the getter.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed better, 👍