Environment
- aws-cdk v1.53.0 or above
- aws-lambda-nodejs
My code
I want to deploy lambda@edge source code by aws-cdk
.
new NodejsFunction(this, 'some-awesome-function', {
role: new Role(this, 'AllowLambdaServiceToAssumeRole', {
assumedBy: new CompositePrincipal(
new ServicePrincipal('lambda.amazonaws.com'),
new ServicePrincipal('edgelambda.amazonaws.com')
),
}),
})
My command
cdk deploy
Error Message
CREATE_FAILED | AWS::CloudFront::Distribution | XXXX/CFDistribution (XXXXCFDistributionXXXX) The function cannot have environment variables. Function: arn:aws:lambda:us-east-1:XXXX:function:CdkStack-XXXXD6AD4BEB-1XXXXXXMFY8E:1 (Service: AmazonCloudFront; Status Code: 400; Error Code: InvalidLambdaFunctionAssociation;
Solution
set awsSdkConnectionReuse
to false
in your props.
new NodejsFunction(this, 'some-awesome-function', {
role: new Role(this, 'AllowLambdaServiceToAssumeRole', {
assumedBy: new CompositePrincipal(
new ServicePrincipal('lambda.amazonaws.com'),
new ServicePrincipal('edgelambda.amazonaws.com')
),
}),
awsSdkConnectionReuse: false,
})
Reason
At July 2020, Lambda@Edge doesn't support Environment Values.
But aws-cdk v1.53.0 update contains default true
of AWS_NODEJS_CONNECTION_REUSE_ENABLED
.
https://github.com/aws/aws-cdk/commit/44c040072362456ebdd15799076a67bbb74e6668
// Enable connection reuse for aws-sdk
if (props.awsSdkConnectionReuse ?? true) {
this.addEnvironment('AWS_NODEJS_CONNECTION_REUSE_ENABLED', '1');
}
So you must set false
the prop.
Top comments (0)