Skip to content

Commit

Permalink
fix: lambda-nodejs default runtime regression (#26763)
Browse files Browse the repository at this point in the history
Previously we changed the default version of the lambda-nodejs Function construct to go from using the `builtInNodeJsCustomResourceRuntime`, a map of regions to available versions, to `lambda.Runtime.NODEJS_18_X`. The default `externalModule` configuration excluded the aws-sdk version based on the runtime passed, excluding v2 for Node16 and under, and v3 for Node18 and up, but users can pass their own bundling configuration excluding `aws-sdk` while not explicitly passing a runtime, which caused their functions to break.

Adds a new `lambda.Runtime` value for `NODEJS_LATEST`. This is central reference for the latest version of NodeJS provided by the lamdba service. It also includes a new property `isLatest` which can be used to indicate that the runtime version may change over time. This can used to indicate that relying on packages shipped with the environment may not be relied upon if the version changes. We default to using the `NODEJS_LATEST` runtime only if the feature flag is enabled. If the flag is not enabled, use `NODEJS_16_X` to keep supporting users current bundling configurations.

Additionally, add a warning to tell users if they are excluding a package from their bundling that we know doesn't exist within the runtime they are using. IE, if using `NODEJS_18_X` and the exclude list includes `aws-sdk`, warn users that it won't be present.

Fixes #26732

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
MrArnoldPalmer committed Aug 16, 2023
1 parent 72481a3 commit 2aa4733
Show file tree
Hide file tree
Showing 30 changed files with 33,448 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"version": "33.0.0",
"files": {
"fc4da43a214bb79ca557ca6c54e8dfcc4f2aabbd6672873b7b3ea417576612f5": {
"source": {
"path": "asset.fc4da43a214bb79ca557ca6c54e8dfcc4f2aabbd6672873b7b3ea417576612f5.bundle",
"packaging": "zip"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "fc4da43a214bb79ca557ca6c54e8dfcc4f2aabbd6672873b7b3ea417576612f5.zip",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
},
"c62c808ec232ccd52772ad7eaab2455102eb17c02f23a48068cc3a0a4f8fe4f7": {
"source": {
"path": "LambdaNodeJsLatestIntegDefaultTestDeployAssertD40B5C28.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "c62c808ec232ccd52772ad7eaab2455102eb17c02f23a48068cc3a0a4f8fe4f7.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
}
},
"dockerImages": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
{
"Resources": {
"LambdaInvoked00748c118c58ddbf17c194faa46eda2": {
"Type": "Custom::DeployAssert@SdkCallLambdainvoke",
"Properties": {
"ServiceToken": {
"Fn::GetAtt": [
"SingletonFunction1488541a7b23466481b69b4408076b81HandlerCD40AE9F",
"Arn"
]
},
"service": "Lambda",
"api": "invoke",
"expected": "{\"$ObjectLike\":{\"StatusCode\":200,\"ExecutedVersion\":\"$LATEST\"}}",
"parameters": {
"FunctionName": {
"Fn::Join": [
"",
[
"\"",
{
"Fn::ImportValue": "cdk-integ-lambda-nodejs-latest:ExportsOutputReflatestFE0D80B6C9B17E6B"
},
"\""
]
]
}
},
"flattenResponse": "false",
"salt": "1692126177944"
},
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
},
"LambdaInvoked00748c118c58ddbf17c194faa46eda2InvokeC0A33EEB": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Fn::ImportValue": "cdk-integ-lambda-nodejs-latest:ExportsOutputReflatestFE0D80B6C9B17E6B"
},
"Principal": {
"Fn::GetAtt": [
"SingletonFunction1488541a7b23466481b69b4408076b81Role37ABCE73",
"Arn"
]
}
}
},
"SingletonFunction1488541a7b23466481b69b4408076b81Role37ABCE73": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
}
}
]
},
"ManagedPolicyArns": [
{
"Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}
],
"Policies": [
{
"PolicyName": "Inline",
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"lambda:Invoke"
],
"Effect": "Allow",
"Resource": [
"*"
]
},
{
"Action": [
"lambda:InvokeFunction"
],
"Effect": "Allow",
"Resource": [
{
"Fn::Join": [
"",
[
"arn:",
{
"Ref": "AWS::Partition"
},
":lambda:",
{
"Ref": "AWS::Region"
},
":",
{
"Ref": "AWS::AccountId"
},
":function:",
{
"Fn::ImportValue": "cdk-integ-lambda-nodejs-latest:ExportsOutputReflatestFE0D80B6C9B17E6B"
}
]
]
}
]
}
]
}
}
]
}
},
"SingletonFunction1488541a7b23466481b69b4408076b81HandlerCD40AE9F": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Runtime": "nodejs18.x",
"Code": {
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "fc4da43a214bb79ca557ca6c54e8dfcc4f2aabbd6672873b7b3ea417576612f5.zip"
},
"Timeout": 120,
"Handler": "index.handler",
"Role": {
"Fn::GetAtt": [
"SingletonFunction1488541a7b23466481b69b4408076b81Role37ABCE73",
"Arn"
]
}
}
}
},
"Outputs": {
"AssertionResultsLambdaInvoked00748c118c58ddbf17c194faa46eda2": {
"Value": {
"Fn::GetAtt": [
"LambdaInvoked00748c118c58ddbf17c194faa46eda2",
"assertion"
]
}
}
},
"Parameters": {
"BootstrapVersion": {
"Type": "AWS::SSM::Parameter::Value<String>",
"Default": "/cdk-bootstrap/hnb659fds/version",
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
}
},
"Rules": {
"CheckBootstrapVersion": {
"Assertions": [
{
"Assert": {
"Fn::Not": [
{
"Fn::Contains": [
[
"1",
"2",
"3",
"4",
"5"
],
{
"Ref": "BootstrapVersion"
}
]
}
]
},
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
}
]
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2aa4733

Please sign in to comment.