diff --git a/examples/examples_nodejs_test.go b/examples/examples_nodejs_test.go index 33237f8bed4..a70e7932a77 100644 --- a/examples/examples_nodejs_test.go +++ b/examples/examples_nodejs_test.go @@ -64,10 +64,52 @@ func TestAccMinimal(t *testing.T) { } func TestAccExpress(t *testing.T) { + // This example is reused to further validate that provisioned CallbackFunctions in Node are working at runtime + // as expected, in particular their default runtime is not deprecated and they can utilize new APIs like the + // fetch() API that is new in the Node 18 runtime. + validate := func(t *testing.T, stack integration.RuntimeValidationStackInfo) { + lambdaRuntime := stack.Outputs["lambdaRuntime"].(string) + t.Logf("Picked the following runtime by default: %v", lambdaRuntime) + + lambdaARN := stack.Outputs["lambdaARN"].(string) + + // Invoke a given Lambda function using Go SDK v2 + sess := getAwsSession(t) + lambdaClient := lambda.New(sess) + result, err := lambdaClient.Invoke(&lambda.InvokeInput{ + FunctionName: aws.String(lambdaARN), + Payload: []byte("{}"), + }) + require.NoError(t, err) + + t.Logf("Raw payload returned by the Lambda: %s", result.Payload) + + type data struct { + StatusCode int `json:"statusCode"` + Body string `json:"body"` + } + var payload data + err = json.Unmarshal(result.Payload, &payload) + require.NoError(t, err) + + require.Equal(t, 200, payload.StatusCode) + + type inner struct { + Message string `json:"message"` + FetchStatus int `json:"fetchStatus"` + } + + var response inner + err = json.Unmarshal([]byte(payload.Body), &response) + require.NoError(t, err) + + assert.Contains(t, response.Message, "Hello, world!") + assert.Equal(t, 200, response.FetchStatus) + } test := getJSBaseOptions(t). With(integration.ProgramTestOptions{ - Dir: filepath.Join(getCwd(t), "express"), - RunUpdateTest: true, + Dir: filepath.Join(getCwd(t), "express"), + ExtraRuntimeValidation: validate, }) skipRefresh(&test) integration.ProgramTest(t, &test) diff --git a/examples/express/index.ts b/examples/express/index.ts index d485628d51a..60563f79fb2 100644 --- a/examples/express/index.ts +++ b/examples/express/index.ts @@ -1,4 +1,4 @@ -// Copyright 2016-2017, Pulumi Corporation. All rights reserved. +// Copyright 2016-2024, Pulumi Corporation. All rights reserved. import * as pulumi from "@pulumi/pulumi"; import * as aws from "@pulumi/aws"; @@ -19,7 +19,17 @@ const lambda = new aws.lambda.CallbackFunction("mylambda", { app.get("/", (req, res) => { console.log("Invoked url: " + req.url); - res.json({ message: hello + "\n\nSucceeded with " + ctx.getRemainingTimeInMillis() + "ms remaining.\n" }); + + // Test fetch. + // Per https://docs.aws.amazon.com/lambda/latest/dg/nodejs-handler.html + // fetch is available in Node.js 18 and later runtimes + fetch('https://www.pulumi.com/robots.txt').then(resp => { + res.json({ + message: hello + "\n\nSucceeded with " + ctx.getRemainingTimeInMillis() + "ms remaining.", + fetchStatus: resp.status, + fetched: resp.text(), + }); + }); }); const server = serverlessExpress.createServer(app); @@ -32,4 +42,7 @@ const lambda = new aws.lambda.CallbackFunction("mylambda", { serverlessExpress.proxy(server, event, context); } } -}, providerOpts); \ No newline at end of file +}, providerOpts); + +export const lambdaARN = lambda.arn; +export const lambdaRuntime = lambda.runtime; diff --git a/provider/cmd/pulumi-resource-aws/schema.json b/provider/cmd/pulumi-resource-aws/schema.json index c0d1c96e2a1..cc223a7be0c 100644 --- a/provider/cmd/pulumi-resource-aws/schema.json +++ b/provider/cmd/pulumi-resource-aws/schema.json @@ -88828,10 +88828,6 @@ "name": "Java8AL2", "value": "java8.al2" }, - { - "name": "NodeJS16dX", - "value": "nodejs16.x" - }, { "name": "NodeJS18dX", "value": "nodejs18.x" @@ -88912,6 +88908,11 @@ "value": "nodejs14.x", "deprecationMessage": "This runtime is now deprecated" }, + { + "name": "NodeJS16dX", + "value": "nodejs16.x", + "deprecationMessage": "This runtime is now deprecated" + }, { "name": "Custom", "value": "provided", diff --git a/provider/resources.go b/provider/resources.go index 09dec9728d6..6630f1330f7 100644 --- a/provider/resources.go +++ b/provider/resources.go @@ -4538,7 +4538,6 @@ compatibility shim in favor of the new "name" field.`) {Value: "java17", Name: "Java17"}, {Value: "java21", Name: "Java21"}, {Value: "java8.al2", Name: "Java8AL2"}, - {Value: "nodejs16.x", Name: "NodeJS16dX"}, {Value: "nodejs18.x", Name: "NodeJS18dX"}, {Value: "nodejs20.x", Name: "NodeJS20dX"}, {Value: "provided.al2", Name: "CustomAL2"}, @@ -4558,6 +4557,7 @@ compatibility shim in favor of the new "name" field.`) deprecateRuntime("nodejs10.x", "NodeJS10dX"), deprecateRuntime("nodejs12.x", "NodeJS12dX"), deprecateRuntime("nodejs14.x", "NodeJS14dX"), + deprecateRuntime("nodejs16.x", "NodeJS16dX"), deprecateRuntime("provided", "Custom"), deprecateRuntime("python2.7", "Python2d7"), deprecateRuntime("python3.6", "Python3d6"), diff --git a/sdk/dotnet/Lambda/Enums.cs b/sdk/dotnet/Lambda/Enums.cs index 542f643377a..97dd6a359f1 100644 --- a/sdk/dotnet/Lambda/Enums.cs +++ b/sdk/dotnet/Lambda/Enums.cs @@ -27,7 +27,6 @@ private Runtime(string value) public static Runtime Java17 { get; } = new Runtime("java17"); public static Runtime Java21 { get; } = new Runtime("java21"); public static Runtime Java8AL2 { get; } = new Runtime("java8.al2"); - public static Runtime NodeJS16dX { get; } = new Runtime("nodejs16.x"); public static Runtime NodeJS18dX { get; } = new Runtime("nodejs18.x"); public static Runtime NodeJS20dX { get; } = new Runtime("nodejs20.x"); public static Runtime CustomAL2 { get; } = new Runtime("provided.al2"); @@ -55,6 +54,8 @@ private Runtime(string value) [Obsolete(@"This runtime is now deprecated")] public static Runtime NodeJS14dX { get; } = new Runtime("nodejs14.x"); [Obsolete(@"This runtime is now deprecated")] + public static Runtime NodeJS16dX { get; } = new Runtime("nodejs16.x"); + [Obsolete(@"This runtime is now deprecated")] public static Runtime Custom { get; } = new Runtime("provided"); [Obsolete(@"This runtime is now deprecated")] public static Runtime Python2d7 { get; } = new Runtime("python2.7"); diff --git a/sdk/go/aws/lambda/pulumiEnums.go b/sdk/go/aws/lambda/pulumiEnums.go index 02f82daaff8..e5bdcee41fd 100644 --- a/sdk/go/aws/lambda/pulumiEnums.go +++ b/sdk/go/aws/lambda/pulumiEnums.go @@ -21,7 +21,6 @@ const ( RuntimeJava17 = Runtime("java17") RuntimeJava21 = Runtime("java21") RuntimeJava8AL2 = Runtime("java8.al2") - RuntimeNodeJS16dX = Runtime("nodejs16.x") RuntimeNodeJS18dX = Runtime("nodejs18.x") RuntimeNodeJS20dX = Runtime("nodejs20.x") RuntimeCustomAL2 = Runtime("provided.al2") @@ -49,6 +48,8 @@ const ( // Deprecated: This runtime is now deprecated RuntimeNodeJS14dX = Runtime("nodejs14.x") // Deprecated: This runtime is now deprecated + RuntimeNodeJS16dX = Runtime("nodejs16.x") + // Deprecated: This runtime is now deprecated RuntimeCustom = Runtime("provided") // Deprecated: This runtime is now deprecated RuntimePython2d7 = Runtime("python2.7") @@ -191,7 +192,6 @@ func (o RuntimePtrOutput) ToStringPtrOutputWithContext(ctx context.Context) pulu // RuntimeJava17 // RuntimeJava21 // RuntimeJava8AL2 -// RuntimeNodeJS16dX // RuntimeNodeJS18dX // RuntimeNodeJS20dX // RuntimeCustomAL2 diff --git a/sdk/java/src/main/java/com/pulumi/aws/lambda/enums/Runtime.java b/sdk/java/src/main/java/com/pulumi/aws/lambda/enums/Runtime.java index cd97106f8b0..e3c95eec248 100644 --- a/sdk/java/src/main/java/com/pulumi/aws/lambda/enums/Runtime.java +++ b/sdk/java/src/main/java/com/pulumi/aws/lambda/enums/Runtime.java @@ -21,7 +21,6 @@ public enum Runtime { Java17("java17"), Java21("java21"), Java8AL2("java8.al2"), - NodeJS16dX("nodejs16.x"), NodeJS18dX("nodejs18.x"), NodeJS20dX("nodejs20.x"), CustomAL2("provided.al2"), @@ -85,6 +84,12 @@ public enum Runtime { * This runtime is now deprecated */ @Deprecated /* This runtime is now deprecated */ + NodeJS16dX("nodejs16.x"), + /** + * @deprecated + * This runtime is now deprecated + */ + @Deprecated /* This runtime is now deprecated */ Custom("provided"), /** * @deprecated diff --git a/sdk/nodejs/lambda/lambdaMixins.ts b/sdk/nodejs/lambda/lambdaMixins.ts index 8cd8f4d774d..43147860a72 100644 --- a/sdk/nodejs/lambda/lambdaMixins.ts +++ b/sdk/nodejs/lambda/lambdaMixins.ts @@ -224,7 +224,7 @@ export type BaseCallbackFunctionArgs = utils.Overwrite> | arn.ARN[]; /** - * The Lambda runtime to use. If not provided, will default to [NodeJS8d10Runtime] + * The Lambda runtime to use. If not provided, will default to [aws.lambda.Runtime.NodeJS20dX]. */ runtime?: Runtime | string; @@ -406,13 +406,11 @@ export class CallbackFunction extends LambdaFunction { // Copy over all option values into the function args. Then overwrite anything we care // about with our own values. This ensures that clients can pass future supported // lambda options without us having to know about it. - // The default version for Lambda functions now is NodeJS16. As of April 30 2022, Node12 - // is EOL/ nodeJS 14 is only in maintenance mode so it's best to upgrade to Node16 const functionArgs = { ...args, code: code, handler: serializedFileNameNoExtension + "." + handlerName, - runtime: args.runtime || Runtime.NodeJS16dX, + runtime: args.runtime || Runtime.NodeJS20dX, role: iam.Role.isInstance(role) ? role.arn : role, timeout: args.timeout === undefined ? 180 : args.timeout, }; diff --git a/sdk/nodejs/types/enums/lambda/index.ts b/sdk/nodejs/types/enums/lambda/index.ts index 01f0b4d9605..2f0e9f4191a 100644 --- a/sdk/nodejs/types/enums/lambda/index.ts +++ b/sdk/nodejs/types/enums/lambda/index.ts @@ -10,7 +10,6 @@ export const Runtime = { Java17: "java17", Java21: "java21", Java8AL2: "java8.al2", - NodeJS16dX: "nodejs16.x", NodeJS18dX: "nodejs18.x", NodeJS20dX: "nodejs20.x", CustomAL2: "provided.al2", @@ -53,6 +52,10 @@ export const Runtime = { * @deprecated This runtime is now deprecated */ NodeJS14dX: "nodejs14.x", + /** + * @deprecated This runtime is now deprecated + */ + NodeJS16dX: "nodejs16.x", /** * @deprecated This runtime is now deprecated */ diff --git a/sdk/python/pulumi_aws/lambda_/_enums.py b/sdk/python/pulumi_aws/lambda_/_enums.py index db8c1ec0833..df872ae2f17 100644 --- a/sdk/python/pulumi_aws/lambda_/_enums.py +++ b/sdk/python/pulumi_aws/lambda_/_enums.py @@ -20,7 +20,6 @@ class Runtime(str, Enum): JAVA17 = "java17" JAVA21 = "java21" JAVA8_AL2 = "java8.al2" - NODE_JS16D_X = "nodejs16.x" NODE_JS18D_X = "nodejs18.x" NODE_JS20D_X = "nodejs20.x" CUSTOM_AL2 = "provided.al2" @@ -39,6 +38,7 @@ class Runtime(str, Enum): NODE_JS10D_X = "nodejs10.x" NODE_JS12D_X = "nodejs12.x" NODE_JS14D_X = "nodejs14.x" + NODE_JS16D_X = "nodejs16.x" CUSTOM = "provided" PYTHON2D7 = "python2.7" PYTHON3D6 = "python3.6"