From 49ad1e02baa223ba3d8f853b8fe9d9ae942220a2 Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Tue, 5 Sep 2023 14:52:53 +0200 Subject: [PATCH 1/6] chore: replace Node16 runtimes in unit tests with symbolic runtime To lower the effort for our next hunt-and-peck Node upgrade, replace all runtimes in unit tests with a symbolic Node version that doesn't actually have to deploy successfully. --- .../test/http/lambda.test.ts | 11 +- .../test/websocket/iam.test.ts | 3 +- .../test/websocket/lambda.test.ts | 5 +- .../test/http/lambda.test.ts | 5 +- .../test/websocket/lambda.test.ts | 5 +- .../lambda/lambda-function-action.test.ts | 5 +- .../test/s3-bucket.test.ts | 3 +- .../test/function.test.ts | 3 +- .../test/s3objectlambda.test.ts | 3 +- .../test/authorizers/lambda.test.ts | 21 ++- .../aws-apigateway/test/cors.test.ts | 3 +- .../aws-apigateway/test/deployment.test.ts | 5 +- .../test/integrations/lambda.test.ts | 15 +- .../aws-apigateway/test/lambda-api.test.ts | 15 +- .../aws-apigateway/test/method.test.ts | 3 +- .../aws-appsync/test/appsync-auth.test.ts | 3 +- .../test/appsync-caching-config.test.ts | 3 +- .../aws-appsync/test/appsync-lambda.test.ts | 7 +- .../test/appsync-mapping-template.test.ts | 3 +- .../test/hooks.test.ts | 7 +- .../aws-cloudfront/test/distribution.test.ts | 9 +- .../test/experimental/edge-function.test.ts | 7 +- .../test/web-distribution.test.ts | 9 +- .../aws-cloudtrail/test/cloudtrail.test.ts | 3 +- .../lambda/custom-deployment-config.test.ts | 3 +- .../test/lambda/deployment-group.test.ts | 3 +- .../test/lambda/lambda-invoke-action.test.ts | 3 +- .../test/pipeline.test.ts | 3 +- .../aws-cognito/test/user-pool.test.ts | 7 +- .../test/api-gateway/api-gateway.test.ts | 3 +- .../test/destinations.test.ts | 3 +- .../test/test-function.ts | 3 +- .../aws-lambda-nodejs/test/bundling.test.ts | 68 +++---- .../lib/helpers-internal/defaults.ts | 13 ++ .../aws-lambda/lib/helpers-internal/index.ts | 1 + .../aws-cdk-lib/aws-lambda/test/adot.test.ts | 3 +- .../aws-cdk-lib/aws-lambda/test/alias.test.ts | 43 ++--- .../aws-lambda/test/architecture.test.ts | 3 +- .../aws-cdk-lib/aws-lambda/test/code.test.ts | 23 +-- .../test/event-source-mapping.test.ts | 3 +- .../aws-lambda/test/function-hash.test.ts | 65 +++---- .../aws-lambda/test/function-url.test.ts | 13 +- .../aws-lambda/test/function.test.ts | 177 +++++++++--------- .../aws-lambda/test/lambda-insights.test.ts | 2 +- .../aws-lambda/test/lambda-version.test.ts | 15 +- .../aws-lambda/test/layers.test.ts | 7 +- .../aws-lambda/test/singleton-lambda.test.ts | 5 +- .../aws-lambda/test/vpc-lambda.test.ts | 21 ++- .../aws-logs-destinations/test/lambda.test.ts | 3 +- .../aws-cdk-lib/aws-rds/test/instance.test.ts | 3 +- .../aws-s3-deployment/test/content.test.ts | 3 +- .../test/lambda/lambda.test.ts | 13 +- .../test/rotation-schedule.test.ts | 13 +- .../aws-secretsmanager/test/secret.test.ts | 3 +- .../aws-ses-actions/test/actions.test.ts | 2 +- .../aws-sns-subscriptions/test/subs.test.ts | 25 +-- .../test/lambda/invoke.test.ts | 3 +- .../custom-resource-provider.test.ts | 21 ++- .../test/provider-framework/provider.test.ts | 27 +-- .../waiter-state-machine.test.ts | 5 +- packages/aws-cdk-lib/package.json | 1 + .../triggers/test/triggers.test.ts | 13 +- 62 files changed, 427 insertions(+), 354 deletions(-) create mode 100644 packages/aws-cdk-lib/aws-lambda/lib/helpers-internal/defaults.ts create mode 100644 packages/aws-cdk-lib/aws-lambda/lib/helpers-internal/index.ts diff --git a/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/http/lambda.test.ts b/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/http/lambda.test.ts index d0dca75302346..2a59960f9c33a 100644 --- a/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/http/lambda.test.ts +++ b/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/http/lambda.test.ts @@ -1,6 +1,7 @@ import { Match, Template } from 'aws-cdk-lib/assertions'; import { HttpApi } from '@aws-cdk/aws-apigatewayv2-alpha'; import { Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda'; +import { DEFAULT_UNITTEST_RUNTIME } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; import { Duration, Stack } from 'aws-cdk-lib'; import { DummyRouteIntegration } from './integration'; import { HttpLambdaAuthorizer, HttpLambdaResponseType } from '../../lib'; @@ -13,7 +14,7 @@ describe('HttpLambdaAuthorizer', () => { const api = new HttpApi(stack, 'HttpApi'); const handler = new Function(stack, 'auth-function', { - runtime: Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: Code.fromInline('exports.handler = () => {return true}'), handler: 'index.handler', }); @@ -49,7 +50,7 @@ describe('HttpLambdaAuthorizer', () => { const api = new HttpApi(stack, 'HttpApi'); const handler = new Function(stack, 'auth-function', { - runtime: Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: Code.fromInline('exports.handler = () => {return true}'), handler: 'index.handler', }); @@ -78,7 +79,7 @@ describe('HttpLambdaAuthorizer', () => { const api = new HttpApi(stack, 'HttpApi'); const handler = new Function(stack, 'auth-function', { - runtime: Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: Code.fromInline('exports.handler = () => {return true}'), handler: 'index.handler', }); @@ -107,7 +108,7 @@ describe('HttpLambdaAuthorizer', () => { const api = new HttpApi(stack, 'HttpApi'); const handler = new Function(stack, 'auth-function', { - runtime: Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: Code.fromInline('exports.handler = () => {return true}'), handler: 'index.handler', }); @@ -136,7 +137,7 @@ describe('HttpLambdaAuthorizer', () => { const api = new HttpApi(stack, 'HttpApi'); const handler = new Function(stack, 'auth-functon', { - runtime: Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: Code.fromInline('exports.handler = () => {return true}'), handler: 'index.handler', }); diff --git a/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/websocket/iam.test.ts b/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/websocket/iam.test.ts index 49d84523a9b90..9bf067ec2b9ce 100644 --- a/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/websocket/iam.test.ts +++ b/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/websocket/iam.test.ts @@ -2,6 +2,7 @@ import { Template } from 'aws-cdk-lib/assertions'; import { WebSocketApi } from '@aws-cdk/aws-apigatewayv2-alpha'; import { WebSocketLambdaIntegration } from '@aws-cdk/aws-apigatewayv2-integrations-alpha'; import { Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda'; +import { DEFAULT_UNITTEST_RUNTIME } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; import { Stack } from 'aws-cdk-lib'; import { WebSocketIamAuthorizer } from '../../lib'; @@ -10,7 +11,7 @@ describe('WebSocketLambdaAuthorizer', () => { const stack = new Stack(); const handler = new Function(stack, 'auth-function', { - runtime: Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: Code.fromInline('exports.handler = () => {return true}'), handler: 'index.handler', }); diff --git a/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/websocket/lambda.test.ts b/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/websocket/lambda.test.ts index e440fa1be1ccd..e1a711d1ac097 100644 --- a/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/websocket/lambda.test.ts +++ b/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/websocket/lambda.test.ts @@ -1,7 +1,8 @@ import { Template } from 'aws-cdk-lib/assertions'; import { WebSocketApi } from '@aws-cdk/aws-apigatewayv2-alpha'; import { WebSocketLambdaIntegration } from '@aws-cdk/aws-apigatewayv2-integrations-alpha'; -import { Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda'; +import { Code, Function } from 'aws-cdk-lib/aws-lambda'; +import { DEFAULT_UNITTEST_RUNTIME } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; import { Stack } from 'aws-cdk-lib'; import { WebSocketLambdaAuthorizer } from '../../lib'; @@ -11,7 +12,7 @@ describe('WebSocketLambdaAuthorizer', () => { const stack = new Stack(); const handler = new Function(stack, 'auth-function', { - runtime: Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: Code.fromInline('exports.handler = () => {return true}'), handler: 'index.handler', }); diff --git a/packages/@aws-cdk/aws-apigatewayv2-integrations-alpha/test/http/lambda.test.ts b/packages/@aws-cdk/aws-apigatewayv2-integrations-alpha/test/http/lambda.test.ts index 23e15f17d4e32..d53d6e6345d67 100644 --- a/packages/@aws-cdk/aws-apigatewayv2-integrations-alpha/test/http/lambda.test.ts +++ b/packages/@aws-cdk/aws-apigatewayv2-integrations-alpha/test/http/lambda.test.ts @@ -1,6 +1,7 @@ import { Match, Template } from 'aws-cdk-lib/assertions'; import { HttpApi, HttpRoute, HttpRouteKey, MappingValue, ParameterMapping, PayloadFormatVersion } from '@aws-cdk/aws-apigatewayv2-alpha'; -import { Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda'; +import { Code, Function } from 'aws-cdk-lib/aws-lambda'; +import { DEFAULT_UNITTEST_RUNTIME } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; import { App, Stack } from 'aws-cdk-lib'; import { HttpLambdaIntegration } from '../../lib'; @@ -111,7 +112,7 @@ describe('LambdaProxyIntegration', () => { function fooFunction(stack: Stack, id: string) { return new Function(stack, id, { code: Code.fromInline('foo'), - runtime: Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', }); } \ No newline at end of file diff --git a/packages/@aws-cdk/aws-apigatewayv2-integrations-alpha/test/websocket/lambda.test.ts b/packages/@aws-cdk/aws-apigatewayv2-integrations-alpha/test/websocket/lambda.test.ts index a890afd970280..530a6bc50e942 100644 --- a/packages/@aws-cdk/aws-apigatewayv2-integrations-alpha/test/websocket/lambda.test.ts +++ b/packages/@aws-cdk/aws-apigatewayv2-integrations-alpha/test/websocket/lambda.test.ts @@ -1,6 +1,7 @@ import { Template } from 'aws-cdk-lib/assertions'; import { WebSocketApi } from '@aws-cdk/aws-apigatewayv2-alpha'; -import { Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda'; +import { Code, Function } from 'aws-cdk-lib/aws-lambda'; +import { DEFAULT_UNITTEST_RUNTIME } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; import { Stack } from 'aws-cdk-lib'; import { WebSocketLambdaIntegration } from '../../lib'; @@ -50,7 +51,7 @@ describe('LambdaWebSocketIntegration', () => { function fooFunction(stack: Stack, id: string) { return new Function(stack, id, { code: Code.fromInline('foo'), - runtime: Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', }); } diff --git a/packages/@aws-cdk/aws-iot-actions-alpha/test/lambda/lambda-function-action.test.ts b/packages/@aws-cdk/aws-iot-actions-alpha/test/lambda/lambda-function-action.test.ts index 4959bc504d7a3..e78e2492529eb 100644 --- a/packages/@aws-cdk/aws-iot-actions-alpha/test/lambda/lambda-function-action.test.ts +++ b/packages/@aws-cdk/aws-iot-actions-alpha/test/lambda/lambda-function-action.test.ts @@ -3,6 +3,7 @@ import * as iot from '@aws-cdk/aws-iot-alpha'; import * as lambda from 'aws-cdk-lib/aws-lambda'; import * as cdk from 'aws-cdk-lib'; import * as actions from '../../lib'; +import { DEFAULT_UNITTEST_RUNTIME } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; test('create a topic rule with lambda action and a lambda permission to be invoked by the topic rule', () => { // GIVEN @@ -11,7 +12,7 @@ test('create a topic rule with lambda action and a lambda permission to be invok sql: iot.IotSql.fromStringAsVer20160323("SELECT topic(2) as device_id FROM 'device/+/data'"), }); const func = new lambda.Function(stack, 'MyFunction', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', code: lambda.Code.fromInline('console.log("foo")'), }); @@ -60,7 +61,7 @@ test('create two different permissions, when two topic rules have the same actio // GIVEN const stack = new cdk.Stack(); const func = new lambda.Function(stack, 'MyFunction', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', code: lambda.Code.fromInline('console.log("foo")'), }); diff --git a/packages/@aws-cdk/aws-kinesisfirehose-destinations-alpha/test/s3-bucket.test.ts b/packages/@aws-cdk/aws-kinesisfirehose-destinations-alpha/test/s3-bucket.test.ts index 457fd2695d0e7..6dde373dbf332 100644 --- a/packages/@aws-cdk/aws-kinesisfirehose-destinations-alpha/test/s3-bucket.test.ts +++ b/packages/@aws-cdk/aws-kinesisfirehose-destinations-alpha/test/s3-bucket.test.ts @@ -3,6 +3,7 @@ import * as iam from 'aws-cdk-lib/aws-iam'; import * as firehose from '@aws-cdk/aws-kinesisfirehose-alpha'; import * as kms from 'aws-cdk-lib/aws-kms'; import * as lambda from 'aws-cdk-lib/aws-lambda'; +import { DEFAULT_UNITTEST_RUNTIME } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; import * as logs from 'aws-cdk-lib/aws-logs'; import * as s3 from 'aws-cdk-lib/aws-s3'; import * as cdk from 'aws-cdk-lib'; @@ -240,7 +241,7 @@ describe('S3 destination', () => { beforeEach(() => { lambdaFunction = new lambda.Function(stack, 'DataProcessorFunction', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('foo'), handler: 'bar', }); diff --git a/packages/@aws-cdk/aws-lambda-python-alpha/test/function.test.ts b/packages/@aws-cdk/aws-lambda-python-alpha/test/function.test.ts index e04571cc025b1..2d60c6210428b 100644 --- a/packages/@aws-cdk/aws-lambda-python-alpha/test/function.test.ts +++ b/packages/@aws-cdk/aws-lambda-python-alpha/test/function.test.ts @@ -1,6 +1,7 @@ import * as path from 'path'; import { Template } from 'aws-cdk-lib/assertions'; import { Code, Runtime } from 'aws-cdk-lib/aws-lambda'; +import { DEFAULT_UNITTEST_RUNTIME } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; import { AssetHashType, DockerImage, Stack } from 'aws-cdk-lib'; import { PythonFunction } from '../lib'; import { Bundling, BundlingProps } from '../lib/bundling'; @@ -112,7 +113,7 @@ test('throws when entry does not exist', () => { test('throws with the wrong runtime family', () => { expect(() => new PythonFunction(stack, 'handler1', { entry: path.join(__dirname, 'lambda-handler'), - runtime: Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, })).toThrow(/Only `PYTHON` runtimes are supported/); }); diff --git a/packages/@aws-cdk/aws-s3objectlambda-alpha/test/s3objectlambda.test.ts b/packages/@aws-cdk/aws-s3objectlambda-alpha/test/s3objectlambda.test.ts index 414ecb0444d1b..024f74b2c00ed 100644 --- a/packages/@aws-cdk/aws-s3objectlambda-alpha/test/s3objectlambda.test.ts +++ b/packages/@aws-cdk/aws-s3objectlambda-alpha/test/s3objectlambda.test.ts @@ -1,5 +1,6 @@ import { Template } from 'aws-cdk-lib/assertions'; import * as lambda from 'aws-cdk-lib/aws-lambda'; +import { DEFAULT_UNITTEST_RUNTIME } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; import * as s3 from 'aws-cdk-lib/aws-s3'; import * as cdk from 'aws-cdk-lib'; import { AccessPoint } from '../lib'; @@ -12,7 +13,7 @@ beforeEach(() => { stack = new cdk.Stack(); bucket = new s3.Bucket(stack, 'MyBucket'); handler = new lambda.Function(stack, 'MyFunction', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.hello', code: new lambda.InlineCode('def hello(): pass'), }); diff --git a/packages/aws-cdk-lib/aws-apigateway/test/authorizers/lambda.test.ts b/packages/aws-cdk-lib/aws-apigateway/test/authorizers/lambda.test.ts index 7eea5ca1ec00e..b100d65f39b03 100644 --- a/packages/aws-cdk-lib/aws-apigateway/test/authorizers/lambda.test.ts +++ b/packages/aws-cdk-lib/aws-apigateway/test/authorizers/lambda.test.ts @@ -1,6 +1,7 @@ import { Match, Template } from '../../../assertions'; import * as iam from '../../../aws-iam'; import * as lambda from '../../../aws-lambda'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../../aws-lambda/lib/helpers-internal'; import { Duration, Stack } from '../../../core'; import { AuthorizationType, IdentitySource, RequestAuthorizer, RestApi, TokenAuthorizer } from '../../lib'; @@ -11,7 +12,7 @@ describe('lambda authorizer', () => { const func = new lambda.Function(stack, 'myfunction', { handler: 'handler', code: lambda.Code.fromInline('foo'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const auth = new TokenAuthorizer(stack, 'myauthorizer', { @@ -84,7 +85,7 @@ describe('lambda authorizer', () => { const func = new lambda.Function(stack, 'myfunction', { handler: 'handler', code: lambda.Code.fromInline('foo'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const auth = new RequestAuthorizer(stack, 'myauthorizer', { @@ -159,7 +160,7 @@ describe('lambda authorizer', () => { const func = new lambda.Function(stack, 'myfunction', { handler: 'handler', code: lambda.Code.fromInline('foo'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); expect(() => new RequestAuthorizer(stack, 'myauthorizer', { @@ -175,7 +176,7 @@ describe('lambda authorizer', () => { const func = new lambda.Function(stack, 'myfunction', { handler: 'handler', code: lambda.Code.fromInline('foo'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const auth = new TokenAuthorizer(stack, 'myauthorizer', { @@ -248,7 +249,7 @@ describe('lambda authorizer', () => { const func = new lambda.Function(stack, 'myfunction', { handler: 'handler', code: lambda.Code.fromInline('foo'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const auth = new RequestAuthorizer(stack, 'myauthorizer', { @@ -319,7 +320,7 @@ describe('lambda authorizer', () => { const func = new lambda.Function(stack, 'myfunction', { handler: 'handler', code: lambda.Code.fromInline('foo'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const role = new iam.Role(stack, 'authorizerassumerole', { @@ -409,7 +410,7 @@ describe('lambda authorizer', () => { const func = new lambda.Function(stack, 'myfunction', { handler: 'handler', code: lambda.Code.fromInline('foo'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const role = new iam.Role(stack, 'authorizerassumerole', { @@ -500,7 +501,7 @@ describe('lambda authorizer', () => { const func = new lambda.Function(stack, 'myfunction', { handler: 'handler', code: lambda.Code.fromInline('foo'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const auth = new TokenAuthorizer(stack, 'myauthorizer', { handler: func, @@ -514,7 +515,7 @@ describe('lambda authorizer', () => { const func = new lambda.Function(stack, 'myfunction', { handler: 'handler', code: lambda.Code.fromInline('foo'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const auth = new RequestAuthorizer(stack, 'myauthorizer', { handler: func, @@ -559,7 +560,7 @@ describe('lambda authorizer', () => { const func = new lambda.Function(stack, 'myfunction', { handler: 'handler', code: lambda.Code.fromInline('foo'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const auth = new RequestAuthorizer(stack, 'myauthorizer', { diff --git a/packages/aws-cdk-lib/aws-apigateway/test/cors.test.ts b/packages/aws-cdk-lib/aws-apigateway/test/cors.test.ts index 19d0e6548a72f..17f5589dda4ce 100644 --- a/packages/aws-cdk-lib/aws-apigateway/test/cors.test.ts +++ b/packages/aws-cdk-lib/aws-apigateway/test/cors.test.ts @@ -1,5 +1,6 @@ import { Template } from '../../assertions'; import * as lambda from '../../aws-lambda'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; import { Duration, Stack } from '../../core'; import * as apigw from '../lib'; @@ -634,7 +635,7 @@ describe('cors', () => { const handler = new lambda.Function(stack, 'handler', { handler: 'index.handler', code: lambda.Code.fromInline('boom'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); // WHEN diff --git a/packages/aws-cdk-lib/aws-apigateway/test/deployment.test.ts b/packages/aws-cdk-lib/aws-apigateway/test/deployment.test.ts index eefc4bfd9bf97..fe2795756e4d8 100644 --- a/packages/aws-cdk-lib/aws-apigateway/test/deployment.test.ts +++ b/packages/aws-cdk-lib/aws-apigateway/test/deployment.test.ts @@ -1,6 +1,7 @@ import * as path from 'path'; import { Template } from '../../assertions'; import * as lambda from '../../aws-lambda'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; import { CfnResource, Lazy, Stack } from '../../core'; import * as apigateway from '../lib'; @@ -198,12 +199,12 @@ describe('deployment', () => { const stack2 = new Stack(); const handler1 = new lambda.Function(stack1, 'handler1', { code: lambda.Code.fromAsset(path.join(__dirname, 'lambda')), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', }); const handler2 = new lambda.Function(stack2, 'handler2', { code: lambda.Code.fromAsset(path.join(__dirname, 'lambda')), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', }); diff --git a/packages/aws-cdk-lib/aws-apigateway/test/integrations/lambda.test.ts b/packages/aws-cdk-lib/aws-apigateway/test/integrations/lambda.test.ts index fcbbc85f50050..fe2ed328c085c 100644 --- a/packages/aws-cdk-lib/aws-apigateway/test/integrations/lambda.test.ts +++ b/packages/aws-cdk-lib/aws-apigateway/test/integrations/lambda.test.ts @@ -1,5 +1,6 @@ import { Match, Template } from '../../../assertions'; import * as lambda from '../../../aws-lambda'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../../aws-lambda/lib/helpers-internal'; import * as cdk from '../../../core'; import * as apigateway from '../../lib'; @@ -54,7 +55,7 @@ describe('lambda', () => { // GIVEN const stack = new cdk.Stack(); const fn = new lambda.Function(stack, 'Handler', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('foo'), handler: 'index.handler', }); @@ -102,7 +103,7 @@ describe('lambda', () => { // GIVEN const stack = new cdk.Stack(); const fn = new lambda.Function(stack, 'Handler', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('foo'), handler: 'index.handler', }); @@ -138,7 +139,7 @@ describe('lambda', () => { // GIVEN const stack = new cdk.Stack(); const fn = new lambda.Function(stack, 'Handler', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('foo'), handler: 'index.handler', }); @@ -162,7 +163,7 @@ describe('lambda', () => { const api = new apigateway.RestApi(stack, 'test-api'); const handler = new lambda.Function(stack, 'MyFunc', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', code: lambda.Code.fromInline('loo'), }); @@ -228,7 +229,7 @@ describe('lambda', () => { }); const handler = new lambda.Function(stack, 'MyFunc', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', code: lambda.Code.fromInline('loo'), }); @@ -249,7 +250,7 @@ describe('lambda', () => { const method = restapi.root.addMethod('ANY'); const handler = new lambda.Function(stack, 'MyFunc', { functionName: 'ThisFunction', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', code: lambda.Code.fromInline('loo'), }); @@ -269,7 +270,7 @@ describe('lambda', () => { const restapi = new apigateway.RestApi(stack, 'RestApi'); const method = restapi.root.addMethod('ANY'); const handler = new lambda.Function(stack, 'MyFunc', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', code: lambda.Code.fromInline('loo'), }); diff --git a/packages/aws-cdk-lib/aws-apigateway/test/lambda-api.test.ts b/packages/aws-cdk-lib/aws-apigateway/test/lambda-api.test.ts index 0db0f46ed9e79..5092af31d60f4 100644 --- a/packages/aws-cdk-lib/aws-apigateway/test/lambda-api.test.ts +++ b/packages/aws-cdk-lib/aws-apigateway/test/lambda-api.test.ts @@ -1,5 +1,6 @@ import { Match, Template } from '../../assertions'; import * as lambda from '../../aws-lambda'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; import * as cdk from '../../core'; import * as apigw from '../lib'; import { LambdaRestApi } from '../lib'; @@ -12,7 +13,7 @@ describe('lambda api', () => { const handler = new lambda.Function(stack, 'handler', { handler: 'index.handler', code: lambda.Code.fromInline('boom'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); // WHEN @@ -74,7 +75,7 @@ describe('lambda api', () => { const handler = new lambda.Function(stack, 'handler', { handler: 'index.handler', code: lambda.Code.fromInline('boom'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const alias = new lambda.Alias(stack, 'alias', { aliasName: 'my-alias', @@ -139,7 +140,7 @@ describe('lambda api', () => { const handler = new lambda.Function(stack, 'handler', { handler: 'index.handler', code: lambda.Code.fromInline('boom'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); // WHEN @@ -203,7 +204,7 @@ describe('lambda api', () => { const handler = new lambda.Function(stack, 'handler', { handler: 'index.handler', code: lambda.Code.fromInline('boom'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); expect(() => new apigw.LambdaRestApi(stack, 'lambda-rest-api', { @@ -224,7 +225,7 @@ describe('lambda api', () => { const handler = new lambda.Function(stack, 'handler', { handler: 'index.handler', code: lambda.Code.fromInline('boom'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); // WHEN @@ -278,7 +279,7 @@ describe('lambda api', () => { const handler = new lambda.Function(stack, 'handler', { handler: 'index.handler', code: lambda.Code.fromInline('boom'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); // WHEN @@ -340,7 +341,7 @@ describe('lambda api', () => { handler: new lambda.Function(stack, 'handler', { handler: 'index.handler', code: lambda.Code.fromInline('boom'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }), restApiName: cdk.PhysicalName.GENERATE_IF_NEEDED, }); diff --git a/packages/aws-cdk-lib/aws-apigateway/test/method.test.ts b/packages/aws-cdk-lib/aws-apigateway/test/method.test.ts index 0201eada97ce8..bbf4c1bbd8a24 100644 --- a/packages/aws-cdk-lib/aws-apigateway/test/method.test.ts +++ b/packages/aws-cdk-lib/aws-apigateway/test/method.test.ts @@ -4,6 +4,7 @@ import * as iam from '../../aws-iam'; import * as lambda from '../../aws-lambda'; import * as cdk from '../../core'; import * as apigw from '../lib'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; const DUMMY_AUTHORIZER: apigw.IAuthorizer = { authorizerId: 'dummyauthorizer', @@ -643,7 +644,7 @@ describe('method', () => { const func = new lambda.Function(stack, 'myfunction', { handler: 'handler', code: lambda.Code.fromInline('foo'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const auth = new apigw.TokenAuthorizer(stack, 'myauthorizer1', { diff --git a/packages/aws-cdk-lib/aws-appsync/test/appsync-auth.test.ts b/packages/aws-cdk-lib/aws-appsync/test/appsync-auth.test.ts index 7503303a29623..5ae168d19c323 100644 --- a/packages/aws-cdk-lib/aws-appsync/test/appsync-auth.test.ts +++ b/packages/aws-cdk-lib/aws-appsync/test/appsync-auth.test.ts @@ -4,6 +4,7 @@ import * as cognito from '../../aws-cognito'; import * as lambda from '../../aws-lambda'; import * as cdk from '../../core'; import * as appsync from '../lib'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; // GIVEN let stack: cdk.Stack; @@ -637,7 +638,7 @@ describe('AppSync Lambda Authorization', () => { let fn: lambda.Function; beforeEach(() => { fn = new lambda.Function(stack, 'auth-function', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', code: lambda.Code.fromInline('/* lambda authentication code here.*/'), }); diff --git a/packages/aws-cdk-lib/aws-appsync/test/appsync-caching-config.test.ts b/packages/aws-cdk-lib/aws-appsync/test/appsync-caching-config.test.ts index 8ccaeacb4ed1f..6a50665d2ec8b 100644 --- a/packages/aws-cdk-lib/aws-appsync/test/appsync-caching-config.test.ts +++ b/packages/aws-cdk-lib/aws-appsync/test/appsync-caching-config.test.ts @@ -4,6 +4,7 @@ import * as lambda from '../../aws-lambda'; import * as cdk from '../../core'; import { Duration } from '../../core'; import * as appsync from '../lib'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; let stack: cdk.Stack; let api: appsync.GraphqlApi; @@ -25,7 +26,7 @@ describe('Lambda caching config', () => { func = new lambda.Function(stack, 'func', { code: lambda.Code.fromAsset(path.join(__dirname, 'verify/lambda-tutorial')), handler: 'lambda-tutorial.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); }); diff --git a/packages/aws-cdk-lib/aws-appsync/test/appsync-lambda.test.ts b/packages/aws-cdk-lib/aws-appsync/test/appsync-lambda.test.ts index 2d3db2414db17..b497d143dd386 100644 --- a/packages/aws-cdk-lib/aws-appsync/test/appsync-lambda.test.ts +++ b/packages/aws-cdk-lib/aws-appsync/test/appsync-lambda.test.ts @@ -3,6 +3,7 @@ import { Template } from '../../assertions'; import * as lambda from '../../aws-lambda'; import * as cdk from '../../core'; import * as appsync from '../lib'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; // GLOBAL GIVEN let stack: cdk.Stack; @@ -22,7 +23,7 @@ describe('Lambda Data Source configuration', () => { func = new lambda.Function(stack, 'func', { code: lambda.Code.fromAsset(path.join(__dirname, 'verify/iam-query')), handler: 'iam-query.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); }); @@ -78,7 +79,7 @@ describe('Lambda Data Source configuration', () => { const dummyFunction = new lambda.Function(newStack, 'func', { code: lambda.Code.fromAsset(path.join(__dirname, 'verify/iam-query')), handler: 'iam-query.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); graphqlapi.addLambdaDataSource(`data-${badCharacter}-source`, dummyFunction); @@ -132,7 +133,7 @@ describe('adding lambda data source from imported api', () => { func = new lambda.Function(stack, 'func', { code: lambda.Code.fromAsset(path.join(__dirname, 'verify/iam-query')), handler: 'iam-query.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); }); diff --git a/packages/aws-cdk-lib/aws-appsync/test/appsync-mapping-template.test.ts b/packages/aws-cdk-lib/aws-appsync/test/appsync-mapping-template.test.ts index 06a5f268273aa..aceacc39d8eef 100644 --- a/packages/aws-cdk-lib/aws-appsync/test/appsync-mapping-template.test.ts +++ b/packages/aws-cdk-lib/aws-appsync/test/appsync-mapping-template.test.ts @@ -3,6 +3,7 @@ import { Template } from '../../assertions'; import * as lambda from '../../aws-lambda'; import * as cdk from '../../core'; import * as appsync from '../lib'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; let stack: cdk.Stack; let api: appsync.GraphqlApi; @@ -26,7 +27,7 @@ describe('Lambda Mapping Templates', () => { func = new lambda.Function(stack, 'func', { code: lambda.Code.fromAsset(path.join(__dirname, 'verify/lambda-tutorial')), handler: 'lambda-tutorial.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); }); diff --git a/packages/aws-cdk-lib/aws-autoscaling-hooktargets/test/hooks.test.ts b/packages/aws-cdk-lib/aws-autoscaling-hooktargets/test/hooks.test.ts index bdb213389f736..a32359bb5bac9 100644 --- a/packages/aws-cdk-lib/aws-autoscaling-hooktargets/test/hooks.test.ts +++ b/packages/aws-cdk-lib/aws-autoscaling-hooktargets/test/hooks.test.ts @@ -4,6 +4,7 @@ import * as ec2 from '../../aws-ec2'; import * as iam from '../../aws-iam'; import * as kms from '../../aws-kms'; import * as lambda from '../../aws-lambda'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; import * as sns from '../../aws-sns'; import * as sqs from '../../aws-sqs'; import { Stack } from '../../core'; @@ -120,7 +121,7 @@ describe('given an AutoScalingGroup and no role', () => { // GIVEN const fn = new lambda.Function(stack, 'Fn', { code: lambda.Code.fromInline('foo'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.index', }); @@ -164,7 +165,7 @@ describe('given an AutoScalingGroup and no role', () => { const key = new kms.Key(stack, 'key'); const fn = new lambda.Function(stack, 'Fn', { code: lambda.Code.fromInline('foo'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.index', }); @@ -296,7 +297,7 @@ describe('given an AutoScalingGroup and a role', () => { // GIVEN const fn = new lambda.Function(stack, 'Fn', { code: lambda.Code.fromInline('foo'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.index', }); const myrole = new iam.Role(stack, 'MyRole', { diff --git a/packages/aws-cdk-lib/aws-cloudfront/test/distribution.test.ts b/packages/aws-cdk-lib/aws-cloudfront/test/distribution.test.ts index 87ce34ad9e538..559dbd6008e0f 100644 --- a/packages/aws-cdk-lib/aws-cloudfront/test/distribution.test.ts +++ b/packages/aws-cdk-lib/aws-cloudfront/test/distribution.test.ts @@ -22,6 +22,7 @@ import { SecurityPolicyProtocol, SSLMethod, } from '../lib'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; let app: App; let stack: Stack; @@ -666,7 +667,7 @@ describe('with Lambda@Edge functions', () => { beforeEach(() => { lambdaFunction = new lambda.Function(stack, 'Function', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('whatever'), handler: 'index.handler', }); @@ -794,7 +795,7 @@ describe('with Lambda@Edge functions', () => { test('with removable env vars', () => { const envLambdaFunction = new lambda.Function(stack, 'EnvFunction', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('whateverwithenv'), handler: 'index.handler', }); @@ -822,7 +823,7 @@ describe('with Lambda@Edge functions', () => { test('with incompatible env vars', () => { const envLambdaFunction = new lambda.Function(stack, 'EnvFunction', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('whateverwithenv'), handler: 'index.handler', environment: { @@ -848,7 +849,7 @@ describe('with Lambda@Edge functions', () => { test('with singleton function', () => { const singleton = new lambda.SingletonFunction(stack, 'Singleton', { uuid: 'singleton-for-cloudfront', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('code'), handler: 'index.handler', }); diff --git a/packages/aws-cdk-lib/aws-cloudfront/test/experimental/edge-function.test.ts b/packages/aws-cdk-lib/aws-cloudfront/test/experimental/edge-function.test.ts index 1c7796b04a987..aebaa68d1edf5 100644 --- a/packages/aws-cdk-lib/aws-cloudfront/test/experimental/edge-function.test.ts +++ b/packages/aws-cdk-lib/aws-cloudfront/test/experimental/edge-function.test.ts @@ -5,6 +5,7 @@ import * as iam from '../../../aws-iam'; import * as lambda from '../../../aws-lambda'; import * as cdk from '../../../core'; import * as cloudfront from '../../lib'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../../aws-lambda/lib/helpers-internal'; let app: cdk.App; let stack: cdk.Stack; @@ -90,7 +91,7 @@ describe('stacks', () => { Code: { ZipFile: 'foo' }, Handler: 'index.handler', Role: { 'Fn::GetAtt': ['MyFnServiceRoleF3016589', 'Arn'] }, - Runtime: 'nodejs16.x', + Runtime: 'nodejs99.x', }); Template.fromStack(fnStack).hasResourceProperties('AWS::Lambda::Version', { FunctionName: { Ref: 'MyFn6F8F742F' }, @@ -152,7 +153,7 @@ describe('stacks', () => { Code: { ZipFile: 'foo' }, Handler: 'index.handler', Role: { 'Fn::GetAtt': ['MyFnServiceRole3F9D41E1', 'Arn'] }, - Runtime: 'nodejs16.x', + Runtime: 'nodejs99.x', }); Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Version', { FunctionName: { Ref: 'MyFn223608AD' }, @@ -310,7 +311,7 @@ function defaultEdgeFunctionProps(stackId?: string) { return { code: lambda.Code.fromInline('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, stackId: stackId, }; } diff --git a/packages/aws-cdk-lib/aws-cloudfront/test/web-distribution.test.ts b/packages/aws-cdk-lib/aws-cloudfront/test/web-distribution.test.ts index 4dbd775fa24b2..12d0b9faf9f6b 100644 --- a/packages/aws-cdk-lib/aws-cloudfront/test/web-distribution.test.ts +++ b/packages/aws-cdk-lib/aws-cloudfront/test/web-distribution.test.ts @@ -21,6 +21,7 @@ import { ViewerCertificate, ViewerProtocolPolicy, } from '../lib'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; /* eslint-disable quote-props */ @@ -837,7 +838,7 @@ added the ellipsis so a user would know there was more to r...`, const lambdaFunction = new lambda.Function(stack, 'Lambda', { code: lambda.Code.fromInline('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); new CloudFrontWebDistribution(stack, 'AnAmazingWebsiteProbably', { @@ -886,7 +887,7 @@ added the ellipsis so a user would know there was more to r...`, const lambdaFunction = new lambda.Function(stack, 'Lambda', { code: lambda.Code.fromInline('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); lambdaFunction.addEnvironment('KEY', 'value', { removeInEdge: true }); @@ -923,7 +924,7 @@ added the ellipsis so a user would know there was more to r...`, const lambdaFunction = new lambda.Function(stack, 'Lambda', { code: lambda.Code.fromInline('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, environment: { KEY: 'value', }, @@ -1307,7 +1308,7 @@ added the ellipsis so a user would know there was more to r...`, const fn = new lambda.Function(stack, 'Lambda', { code: lambda.Code.fromInline('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const lambdaVersion = new lambda.Version(stack, 'LambdaVersion', { lambda: fn }); diff --git a/packages/aws-cdk-lib/aws-cloudtrail/test/cloudtrail.test.ts b/packages/aws-cdk-lib/aws-cloudtrail/test/cloudtrail.test.ts index 33e611b902a4e..798b791150604 100644 --- a/packages/aws-cdk-lib/aws-cloudtrail/test/cloudtrail.test.ts +++ b/packages/aws-cdk-lib/aws-cloudtrail/test/cloudtrail.test.ts @@ -8,6 +8,7 @@ import * as s3 from '../../aws-s3'; import * as sns from '../../aws-sns'; import { Stack } from '../../core'; import { ManagementEventSources, ReadWriteType, Trail, InsightType } from '../lib'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; const ExpectedBucketPolicyProperties = { PolicyDocument: { @@ -571,7 +572,7 @@ describe('cloudtrail', () => { test('for Lambda function data event', () => { const stack = getTestStack(); const lambdaFunction = new lambda.Function(stack, 'LambdaFunction', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'hello.handler', code: lambda.Code.fromInline('exports.handler = {}'), }); diff --git a/packages/aws-cdk-lib/aws-codedeploy/test/lambda/custom-deployment-config.test.ts b/packages/aws-cdk-lib/aws-codedeploy/test/lambda/custom-deployment-config.test.ts index 80ccbf26347f1..3fa30560563d9 100644 --- a/packages/aws-cdk-lib/aws-codedeploy/test/lambda/custom-deployment-config.test.ts +++ b/packages/aws-cdk-lib/aws-codedeploy/test/lambda/custom-deployment-config.test.ts @@ -1,6 +1,7 @@ import { testDeprecated } from '@aws-cdk/cdk-build-tools'; import { Template } from '../../../assertions'; import * as lambda from '../../../aws-lambda'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../../aws-lambda/lib/helpers-internal'; import * as cdk from '../../../core'; import * as codedeploy from '../../lib'; @@ -8,7 +9,7 @@ function mockFunction(stack: cdk.Stack, id: string) { return new lambda.Function(stack, id, { code: lambda.Code.fromInline('mock'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); } function mockAlias(stack: cdk.Stack) { diff --git a/packages/aws-cdk-lib/aws-codedeploy/test/lambda/deployment-group.test.ts b/packages/aws-cdk-lib/aws-codedeploy/test/lambda/deployment-group.test.ts index 6d59bbdd6cb45..653fd2be5c20f 100644 --- a/packages/aws-cdk-lib/aws-codedeploy/test/lambda/deployment-group.test.ts +++ b/packages/aws-cdk-lib/aws-codedeploy/test/lambda/deployment-group.test.ts @@ -2,6 +2,7 @@ import { Match, Template } from '../../../assertions'; import * as cloudwatch from '../../../aws-cloudwatch'; import * as iam from '../../../aws-iam'; import * as lambda from '../../../aws-lambda'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../../aws-lambda/lib/helpers-internal'; import * as cdk from '../../../core'; import { Stack } from '../../../core'; import * as codedeploy from '../../lib'; @@ -11,7 +12,7 @@ function mockFunction(stack: cdk.Stack, id: string) { return new lambda.Function(stack, id, { code: lambda.Code.fromInline('mock'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); } function mockAlias(stack: cdk.Stack) { diff --git a/packages/aws-cdk-lib/aws-codepipeline-actions/test/lambda/lambda-invoke-action.test.ts b/packages/aws-cdk-lib/aws-codepipeline-actions/test/lambda/lambda-invoke-action.test.ts index 7cea2bd59406e..f21b7061050a7 100644 --- a/packages/aws-cdk-lib/aws-codepipeline-actions/test/lambda/lambda-invoke-action.test.ts +++ b/packages/aws-cdk-lib/aws-codepipeline-actions/test/lambda/lambda-invoke-action.test.ts @@ -1,6 +1,7 @@ import { Template, Match } from '../../../assertions'; import * as codepipeline from '../../../aws-codepipeline'; import * as lambda from '../../../aws-lambda'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../../aws-lambda/lib/helpers-internal'; import * as s3 from '../../../aws-s3'; import * as sns from '../../../aws-sns'; import { App, Aws, Lazy, SecretValue, Stack, Token } from '../../../core'; @@ -357,7 +358,7 @@ function stackIncludingLambdaInvokeCodePipeline(props: HelperProps, app?: App) { lambda: new lambda.Function(stack, 'Lambda', { code: lambda.Code.fromCfnParameters(), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }), userParameters: props.userParams, userParametersString: props.userParamsString, diff --git a/packages/aws-cdk-lib/aws-codepipeline-actions/test/pipeline.test.ts b/packages/aws-cdk-lib/aws-codepipeline-actions/test/pipeline.test.ts index 0a7f5a589fb53..8d750847700bb 100644 --- a/packages/aws-cdk-lib/aws-codepipeline-actions/test/pipeline.test.ts +++ b/packages/aws-cdk-lib/aws-codepipeline-actions/test/pipeline.test.ts @@ -5,6 +5,7 @@ import * as codepipeline from '../../aws-codepipeline'; import * as targets from '../../aws-events-targets'; import * as iam from '../../aws-iam'; import * as lambda from '../../aws-lambda'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; import * as s3 from '../../aws-s3'; import * as sns from '../../aws-sns'; import { App, Aws, CfnParameter, SecretValue, Stack } from '../../core'; @@ -427,7 +428,7 @@ describe('pipeline', () => { const lambdaFun = new lambda.Function(stack, 'Function', { code: new lambda.InlineCode('bla'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const pipeline = new codepipeline.Pipeline(stack, 'Pipeline'); diff --git a/packages/aws-cdk-lib/aws-cognito/test/user-pool.test.ts b/packages/aws-cdk-lib/aws-cognito/test/user-pool.test.ts index 52fd586f34deb..b24e2cd4b4b6b 100644 --- a/packages/aws-cdk-lib/aws-cognito/test/user-pool.test.ts +++ b/packages/aws-cdk-lib/aws-cognito/test/user-pool.test.ts @@ -6,6 +6,7 @@ import * as kms from '../../aws-kms'; import * as lambda from '../../aws-lambda'; import { CfnParameter, Duration, Stack, Tags } from '../../core'; import { AccountRecovery, Mfa, NumberAttribute, StringAttribute, UserPool, UserPoolIdentityProvider, UserPoolOperation, VerificationEmailStyle, UserPoolEmail, AdvancedSecurityMode } from '../lib'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; describe('User Pool', () => { test('default setup', () => { @@ -520,12 +521,12 @@ describe('User Pool', () => { const fn1 = new lambda.Function(stack, 'fn1', { code: lambda.Code.fromInline('foo'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', }); const fn2 = new lambda.Function(stack, 'fn2', { code: lambda.Code.fromInline('foo'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', }); @@ -2114,7 +2115,7 @@ function fooFunction(scope: Construct, name: string): lambda.IFunction { return new lambda.Function(scope, name, { functionName: name, code: lambda.Code.fromInline('foo'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', }); } diff --git a/packages/aws-cdk-lib/aws-events-targets/test/api-gateway/api-gateway.test.ts b/packages/aws-cdk-lib/aws-events-targets/test/api-gateway/api-gateway.test.ts index d3139db831c9d..7f8cf14ee8e73 100644 --- a/packages/aws-cdk-lib/aws-events-targets/test/api-gateway/api-gateway.test.ts +++ b/packages/aws-cdk-lib/aws-events-targets/test/api-gateway/api-gateway.test.ts @@ -7,6 +7,7 @@ import * as lambda from '../../../aws-lambda'; import * as sqs from '../../../aws-sqs'; import * as cdk from '../../../core'; import * as targets from '../../lib'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../../aws-lambda/lib/helpers-internal'; test('use api gateway rest api as an event rule target', () => { // GIVEN @@ -255,7 +256,7 @@ function newTestRestApi(scope: constructs.Construct, suffix = '') { const lambdaFunctin = new lambda.Function(scope, `MyLambda${suffix}`, { code: new lambda.InlineCode('foo'), handler: 'bar', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); return new api.LambdaRestApi( scope, `MyLambdaRestApi${suffix}`, { handler: lambdaFunctin, diff --git a/packages/aws-cdk-lib/aws-lambda-destinations/test/destinations.test.ts b/packages/aws-cdk-lib/aws-lambda-destinations/test/destinations.test.ts index b3fb47027d4e5..e9f51f184eecc 100644 --- a/packages/aws-cdk-lib/aws-lambda-destinations/test/destinations.test.ts +++ b/packages/aws-cdk-lib/aws-lambda-destinations/test/destinations.test.ts @@ -1,6 +1,7 @@ import { Template } from '../../assertions'; import * as events from '../../aws-events'; import * as lambda from '../../aws-lambda'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; import * as sns from '../../aws-sns'; import * as sqs from '../../aws-sqs'; import { Stack } from '../../core'; @@ -14,7 +15,7 @@ beforeEach(() => { const lambdaProps = { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }; test('event bus as destination', () => { diff --git a/packages/aws-cdk-lib/aws-lambda-event-sources/test/test-function.ts b/packages/aws-cdk-lib/aws-lambda-event-sources/test/test-function.ts index 94a73c88441d3..b296faffee1a4 100644 --- a/packages/aws-cdk-lib/aws-lambda-event-sources/test/test-function.ts +++ b/packages/aws-cdk-lib/aws-lambda-event-sources/test/test-function.ts @@ -1,12 +1,13 @@ import * as constructs from 'constructs'; import * as lambda from '../../aws-lambda'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; export class TestFunction extends lambda.Function { constructor(scope: constructs.Construct, id: string) { super(scope, id, { handler: 'index.handler', code: lambda.Code.fromInline(`exports.handler = ${handler.toString()}`), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); } } diff --git a/packages/aws-cdk-lib/aws-lambda-nodejs/test/bundling.test.ts b/packages/aws-cdk-lib/aws-lambda-nodejs/test/bundling.test.ts index 4d86d89e157d0..39f5a449291aa 100644 --- a/packages/aws-cdk-lib/aws-lambda-nodejs/test/bundling.test.ts +++ b/packages/aws-cdk-lib/aws-lambda-nodejs/test/bundling.test.ts @@ -11,6 +11,8 @@ import { PackageInstallation } from '../lib/package-installation'; import { Charset, LogLevel, OutputFormat, SourceMapMode } from '../lib/types'; import * as util from '../lib/util'; +const STANDARD_RUNTIME = Runtime.NODEJS_16_X; + let detectPackageInstallationMock: jest.SpyInstance; const app = new App(); const stack = new Stack(app, 'MyTestStack'); @@ -46,7 +48,7 @@ test('esbuild bundling in Docker', () => { entry, projectRoot, depsLockFilePath, - runtime: Runtime.NODEJS_16_X, + runtime: STANDARD_RUNTIME, architecture: Architecture.X86_64, environment: { KEY: 'value', @@ -85,7 +87,7 @@ test('esbuild bundling with handler named index.ts', () => { entry: '/project/lib/index.ts', projectRoot, depsLockFilePath, - runtime: Runtime.NODEJS_16_X, + runtime: STANDARD_RUNTIME, architecture: Architecture.X86_64, forceDockerBundling: true, }); @@ -107,7 +109,7 @@ test('esbuild bundling with tsx handler', () => { entry: '/project/lib/handler.tsx', projectRoot, depsLockFilePath, - runtime: Runtime.NODEJS_16_X, + runtime: STANDARD_RUNTIME, architecture: Architecture.X86_64, forceDockerBundling: true, }); @@ -133,7 +135,7 @@ test('esbuild with Windows paths', () => { Bundling.bundle(stack, { entry: 'C:\\my-project\\lib\\entry.ts', - runtime: Runtime.NODEJS_16_X, + runtime: STANDARD_RUNTIME, architecture: Architecture.X86_64, projectRoot: 'C:\\my-project', depsLockFilePath: 'C:\\my-project\\package-lock.json', @@ -157,7 +159,7 @@ test('esbuild bundling with externals and dependencies', () => { entry: __filename, projectRoot: path.dirname(packageLock), depsLockFilePath: packageLock, - runtime: Runtime.NODEJS_16_X, + runtime: STANDARD_RUNTIME, architecture: Architecture.X86_64, externalModules: ['abc'], nodeModules: ['delay'], @@ -187,7 +189,7 @@ test('esbuild bundling with esbuild options', () => { entry, projectRoot, depsLockFilePath, - runtime: Runtime.NODEJS_16_X, + runtime: STANDARD_RUNTIME, architecture: Architecture.X86_64, minify: true, sourceMap: true, @@ -264,7 +266,7 @@ test('esbuild bundling source map default', () => { entry, projectRoot, depsLockFilePath, - runtime: Runtime.NODEJS_16_X, + runtime: STANDARD_RUNTIME, architecture: Architecture.X86_64, sourceMap: true, sourceMapMode: SourceMapMode.DEFAULT, @@ -311,7 +313,7 @@ test('esbuild bundling source map inline', () => { entry, projectRoot, depsLockFilePath, - runtime: Runtime.NODEJS_16_X, + runtime: STANDARD_RUNTIME, architecture: Architecture.X86_64, sourceMap: true, sourceMapMode: SourceMapMode.INLINE, @@ -361,7 +363,7 @@ test('esbuild bundling source map enabled when only source map mode exists', () entry, projectRoot, depsLockFilePath, - runtime: Runtime.NODEJS_16_X, + runtime: STANDARD_RUNTIME, architecture: Architecture.X86_64, sourceMapMode: SourceMapMode.INLINE, }); @@ -387,7 +389,7 @@ test('esbuild bundling throws when sourceMapMode used with false sourceMap', () entry, projectRoot, depsLockFilePath, - runtime: Runtime.NODEJS_16_X, + runtime: STANDARD_RUNTIME, architecture: Architecture.X86_64, sourceMap: false, sourceMapMode: SourceMapMode.INLINE, @@ -401,7 +403,7 @@ test('Detects yarn.lock', () => { entry: __filename, projectRoot: path.dirname(yarnLock), depsLockFilePath: yarnLock, - runtime: Runtime.NODEJS_16_X, + runtime: STANDARD_RUNTIME, architecture: Architecture.X86_64, nodeModules: ['delay'], forceDockerBundling: true, @@ -424,7 +426,7 @@ test('Detects pnpm-lock.yaml', () => { entry: __filename, projectRoot, depsLockFilePath: pnpmLock, - runtime: Runtime.NODEJS_16_X, + runtime: STANDARD_RUNTIME, architecture: Architecture.X86_64, nodeModules: ['delay'], forceDockerBundling: true, @@ -446,7 +448,7 @@ test('with Docker build args', () => { entry, projectRoot, depsLockFilePath, - runtime: Runtime.NODEJS_16_X, + runtime: STANDARD_RUNTIME, architecture: Architecture.X86_64, buildArgs: { HELLO: 'WORLD', @@ -475,7 +477,7 @@ test('Local bundling', () => { entry, projectRoot, depsLockFilePath, - runtime: Runtime.NODEJS_16_X, + runtime: STANDARD_RUNTIME, architecture: Architecture.X86_64, environment: { KEY: 'value', @@ -485,7 +487,7 @@ test('Local bundling', () => { expect(bundler.local).toBeDefined(); - const tryBundle = bundler.local?.tryBundle('/outdir', { image: Runtime.NODEJS_16_X.bundlingDockerImage }); + const tryBundle = bundler.local?.tryBundle('/outdir', { image: STANDARD_RUNTIME.bundlingDockerImage }); expect(tryBundle).toBe(true); expect(spawnSyncMock).toHaveBeenCalledWith( @@ -513,12 +515,12 @@ test('Incorrect esbuild version', () => { entry, projectRoot, depsLockFilePath, - runtime: Runtime.NODEJS_16_X, + runtime: STANDARD_RUNTIME, architecture: Architecture.X86_64, }); expect(() => bundler.local?.tryBundle('/outdir', { - image: Runtime.NODEJS_16_X.bundlingImage, + image: STANDARD_RUNTIME.bundlingImage, })).toThrow(/Expected esbuild version 0.x but got 3.4.5/); }); @@ -527,7 +529,7 @@ test('Custom bundling docker image', () => { entry, projectRoot, depsLockFilePath, - runtime: Runtime.NODEJS_16_X, + runtime: STANDARD_RUNTIME, architecture: Architecture.X86_64, dockerImage: DockerImage.fromRegistry('my-custom-image'), forceDockerBundling: true, @@ -546,7 +548,7 @@ test('with command hooks', () => { entry, projectRoot, depsLockFilePath, - runtime: Runtime.NODEJS_16_X, + runtime: STANDARD_RUNTIME, architecture: Architecture.X86_64, commandHooks: { beforeBundling(inputDir: string, outputDir: string): string[] { @@ -582,7 +584,7 @@ test('esbuild bundling with projectRoot', () => { projectRoot: '/project', depsLockFilePath, tsconfig, - runtime: Runtime.NODEJS_16_X, + runtime: STANDARD_RUNTIME, architecture: Architecture.X86_64, }); @@ -605,7 +607,7 @@ test('esbuild bundling with projectRoot and externals and dependencies', () => { entry: __filename, projectRoot: repoRoot, depsLockFilePath: packageLock, - runtime: Runtime.NODEJS_16_X, + runtime: STANDARD_RUNTIME, architecture: Architecture.X86_64, externalModules: ['abc'], nodeModules: ['delay'], @@ -637,7 +639,7 @@ test('esbuild bundling with pre compilations', () => { entry: __filename.replace('.js', '.ts'), projectRoot: path.dirname(packageLock), depsLockFilePath: packageLock, - runtime: Runtime.NODEJS_16_X, + runtime: STANDARD_RUNTIME, preCompilation: true, forceDockerBundling: true, architecture: Architecture.X86_64, @@ -668,7 +670,7 @@ test('throws with pre compilation and not found tsconfig', () => { entry, projectRoot, depsLockFilePath, - runtime: Runtime.NODEJS_16_X, + runtime: STANDARD_RUNTIME, forceDockerBundling: true, preCompilation: true, architecture: Architecture.X86_64, @@ -682,7 +684,7 @@ test('with custom hash', () => { entry, projectRoot, depsLockFilePath, - runtime: Runtime.NODEJS_16_X, + runtime: STANDARD_RUNTIME, forceDockerBundling: true, assetHash: 'custom', architecture: Architecture.X86_64, @@ -700,7 +702,7 @@ test('Custom bundling entrypoint', () => { entry, projectRoot, depsLockFilePath, - runtime: Runtime.NODEJS_16_X, + runtime: STANDARD_RUNTIME, architecture: Architecture.X86_64, forceDockerBundling: true, entrypoint: ['/cool/entrypoint', '--cool-entrypoint-arg'], @@ -719,7 +721,7 @@ test('Custom bundling volumes', () => { entry, projectRoot, depsLockFilePath, - runtime: Runtime.NODEJS_16_X, + runtime: STANDARD_RUNTIME, architecture: Architecture.X86_64, forceDockerBundling: true, volumes: [{ hostPath: '/host-path', containerPath: '/container-path' }], @@ -738,7 +740,7 @@ test('Custom bundling volumesFrom', () => { entry, projectRoot, depsLockFilePath, - runtime: Runtime.NODEJS_16_X, + runtime: STANDARD_RUNTIME, architecture: Architecture.X86_64, forceDockerBundling: true, volumesFrom: ['777f7dc92da7'], @@ -757,7 +759,7 @@ test('Custom bundling workingDirectory', () => { entry, projectRoot, depsLockFilePath, - runtime: Runtime.NODEJS_16_X, + runtime: STANDARD_RUNTIME, architecture: Architecture.X86_64, forceDockerBundling: true, workingDirectory: '/working-directory', @@ -776,7 +778,7 @@ test('Custom bundling user', () => { entry, projectRoot, depsLockFilePath, - runtime: Runtime.NODEJS_16_X, + runtime: STANDARD_RUNTIME, architecture: Architecture.X86_64, forceDockerBundling: true, user: 'user:group', @@ -795,7 +797,7 @@ test('Custom bundling securityOpt', () => { entry, projectRoot, depsLockFilePath, - runtime: Runtime.NODEJS_16_X, + runtime: STANDARD_RUNTIME, architecture: Architecture.X86_64, forceDockerBundling: true, securityOpt: 'no-new-privileges', @@ -814,7 +816,7 @@ test('Custom bundling network', () => { entry, projectRoot, depsLockFilePath, - runtime: Runtime.NODEJS_16_X, + runtime: STANDARD_RUNTIME, architecture: Architecture.X86_64, forceDockerBundling: true, network: 'host', @@ -833,7 +835,7 @@ test('Custom bundling file copy variant', () => { entry, projectRoot, depsLockFilePath, - runtime: Runtime.NODEJS_16_X, + runtime: STANDARD_RUNTIME, architecture: Architecture.X86_64, forceDockerBundling: true, bundlingFileAccess: BundlingFileAccess.VOLUME_COPY, @@ -872,7 +874,7 @@ test('bundling with <= Node16 warns when sdk v3 is external', () => { entry, projectRoot, depsLockFilePath, - runtime: Runtime.NODEJS_16_X, + runtime: STANDARD_RUNTIME, architecture: Architecture.X86_64, externalModules: ['@aws-sdk/client-s3'], }); diff --git a/packages/aws-cdk-lib/aws-lambda/lib/helpers-internal/defaults.ts b/packages/aws-cdk-lib/aws-lambda/lib/helpers-internal/defaults.ts new file mode 100644 index 0000000000000..54e1eb805b5c5 --- /dev/null +++ b/packages/aws-cdk-lib/aws-lambda/lib/helpers-internal/defaults.ts @@ -0,0 +1,13 @@ +import { Runtime, RuntimeFamily } from '../runtime'; + +/** + * The preferred NodeJS runtime to use for unit tests + * + * We're centralizing these runtimes, and avoiding using any *real* `NODEJS_xx` + * runtimes, so that when it comes time to upgrade Node there are only limited places + * to changed and it will be an easy grep to figure them all out. + */ +export const DEFAULT_UNITTEST_RUNTIME = new Runtime('nodejs99.x', RuntimeFamily.NODEJS, { + supportsInlineCode: true, + supportsSnapStart: true, +}); diff --git a/packages/aws-cdk-lib/aws-lambda/lib/helpers-internal/index.ts b/packages/aws-cdk-lib/aws-lambda/lib/helpers-internal/index.ts new file mode 100644 index 0000000000000..34df3f0254a5f --- /dev/null +++ b/packages/aws-cdk-lib/aws-lambda/lib/helpers-internal/index.ts @@ -0,0 +1 @@ +export * from './defaults'; \ No newline at end of file diff --git a/packages/aws-cdk-lib/aws-lambda/test/adot.test.ts b/packages/aws-cdk-lib/aws-lambda/test/adot.test.ts index 8189a6da43e72..62e64d29d7cda 100644 --- a/packages/aws-cdk-lib/aws-lambda/test/adot.test.ts +++ b/packages/aws-cdk-lib/aws-lambda/test/adot.test.ts @@ -2,6 +2,7 @@ import { Template } from '../../assertions'; import * as s3 from '../../aws-s3'; import * as cdk from '../../core'; import * as lambda from '../lib'; +import { DEFAULT_UNITTEST_RUNTIME } from '../lib/helpers-internal'; describe('ADOT Lambda Layer', () => { @@ -95,7 +96,7 @@ describe('ADOT Lambda Layer', () => { const fn = new lambda.Function(stack, 'Function', { code: new lambda.InlineCode('FooBar'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, architecture: lambda.Architecture.ARM_64, }); diff --git a/packages/aws-cdk-lib/aws-lambda/test/alias.test.ts b/packages/aws-cdk-lib/aws-lambda/test/alias.test.ts index ad9bb91fa4844..793455f14d7ab 100644 --- a/packages/aws-cdk-lib/aws-lambda/test/alias.test.ts +++ b/packages/aws-cdk-lib/aws-lambda/test/alias.test.ts @@ -4,6 +4,7 @@ import * as appscaling from '../../aws-applicationautoscaling'; import * as cloudwatch from '../../aws-cloudwatch'; import { Lazy, Stack } from '../../core'; import * as lambda from '../lib'; +import { DEFAULT_UNITTEST_RUNTIME } from '../lib/helpers-internal'; describe('alias', () => { testDeprecated('version and aliases', () => { @@ -11,7 +12,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const version = fn.addVersion('1'); @@ -37,7 +38,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); new lambda.Alias(stack, 'Alias', { @@ -58,7 +59,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const version = fn.addVersion('NewVersion'); @@ -84,7 +85,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const version1 = fn.addVersion('1'); @@ -114,7 +115,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const pce = 5; @@ -147,7 +148,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const version = fn.currentVersion; @@ -178,7 +179,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const version = fn.currentVersion; @@ -221,7 +222,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); // WHEN: Alias provisionedConcurrencyConfig less than 0 @@ -256,7 +257,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const version = fn.currentVersion; @@ -273,7 +274,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const version = fn.currentVersion; @@ -309,7 +310,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'fn', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); // WHEN @@ -355,7 +356,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'fn', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const alias = new lambda.Alias(stack, 'Alias', { aliasName: 'prod', @@ -396,7 +397,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const alias = new lambda.Alias(stack, 'Alias', { @@ -435,7 +436,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const alias = new lambda.Alias(stack, 'Alias', { @@ -481,7 +482,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const alias = new lambda.Alias(stack, 'Alias', { @@ -511,7 +512,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const alias = new lambda.Alias(stack, 'Alias', { @@ -532,7 +533,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const alias = new lambda.Alias(stack, 'Alias', { @@ -553,7 +554,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const alias = new lambda.Alias(stack, 'Alias', { @@ -586,7 +587,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const alias = new lambda.Alias(stack, 'Alias', { @@ -611,7 +612,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const alias = new lambda.Alias(stack, 'Alias', { @@ -637,7 +638,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const aliasName = 'prod'; const alias = new lambda.Alias(stack, 'Alias', { diff --git a/packages/aws-cdk-lib/aws-lambda/test/architecture.test.ts b/packages/aws-cdk-lib/aws-lambda/test/architecture.test.ts index 7159db20965a6..2378a9ab68f1e 100644 --- a/packages/aws-cdk-lib/aws-lambda/test/architecture.test.ts +++ b/packages/aws-cdk-lib/aws-lambda/test/architecture.test.ts @@ -1,6 +1,7 @@ import { App, Stack } from '../../core'; import * as lambda from '../lib'; +import { DEFAULT_UNITTEST_RUNTIME } from '../lib/helpers-internal'; describe('architecture', () => { const app = new App(); @@ -11,7 +12,7 @@ describe('architecture', () => { const testLambda = new lambda.Function(stack, 'testLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }, ); diff --git a/packages/aws-cdk-lib/aws-lambda/test/code.test.ts b/packages/aws-cdk-lib/aws-lambda/test/code.test.ts index 8c6d3015dd433..077d59e81aaca 100644 --- a/packages/aws-cdk-lib/aws-lambda/test/code.test.ts +++ b/packages/aws-cdk-lib/aws-lambda/test/code.test.ts @@ -4,6 +4,7 @@ import * as ecr from '../../aws-ecr'; import * as cdk from '../../core'; import * as cxapi from '../../cx-api'; import * as lambda from '../lib'; +import { DEFAULT_UNITTEST_RUNTIME } from '../lib/helpers-internal'; /* eslint-disable dot-notation */ @@ -37,13 +38,13 @@ describe('code', () => { // WHEN new lambda.Function(stack, 'Func1', { handler: 'foom', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: directoryAsset, }); new lambda.Function(stack, 'Func2', { handler: 'foom', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: directoryAsset, }); @@ -65,7 +66,7 @@ describe('code', () => { // WHEN new lambda.Function(stack, 'Func1', { code: lambda.Code.fromAsset(location), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'foom', }); @@ -87,14 +88,14 @@ describe('code', () => { const stack1 = new cdk.Stack(app, 'Stack1'); new lambda.Function(stack1, 'Func', { code: asset, - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'foom', }); const stack2 = new cdk.Stack(app, 'Stack2'); expect(() => new lambda.Function(stack2, 'Func', { code: asset, - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'foom', })).toThrow(/already associated/); }); @@ -106,7 +107,7 @@ describe('code', () => { const code = new lambda.CfnParametersCode(); new lambda.Function(stack, 'Function', { code, - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', }); @@ -152,7 +153,7 @@ describe('code', () => { new lambda.Function(stack, 'Function', { code, - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', }); @@ -434,7 +435,7 @@ describe('code', () => { new lambda.Function(stack, 'Fn', { code: lambda.Code.fromDockerBuild(path.join(__dirname, 'docker-build-lambda')), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); // then @@ -460,7 +461,7 @@ describe('code', () => { imagePath: '/my/image/path', }), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); // then @@ -477,7 +478,7 @@ describe('code', () => { imagePath: '/my/image/path/', }), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); // then @@ -486,7 +487,7 @@ describe('code', () => { }); }); -function defineFunction(code: lambda.Code, runtime: lambda.Runtime = lambda.Runtime.NODEJS_16_X) { +function defineFunction(code: lambda.Code, runtime: lambda.Runtime = DEFAULT_UNITTEST_RUNTIME) { const stack = new cdk.Stack(); return new lambda.Function(stack, 'Func', { handler: 'foom', diff --git a/packages/aws-cdk-lib/aws-lambda/test/event-source-mapping.test.ts b/packages/aws-cdk-lib/aws-lambda/test/event-source-mapping.test.ts index 79df6799bb3bb..2954d7793ac12 100644 --- a/packages/aws-cdk-lib/aws-lambda/test/event-source-mapping.test.ts +++ b/packages/aws-cdk-lib/aws-lambda/test/event-source-mapping.test.ts @@ -1,6 +1,7 @@ import { Match, Template } from '../../assertions'; import * as cdk from '../../core'; import { Code, EventSourceMapping, Function, Runtime, Alias, StartingPosition, FilterRule, FilterCriteria } from '../lib'; +import { DEFAULT_UNITTEST_RUNTIME } from '../lib/helpers-internal'; let stack: cdk.Stack; let fn: Function; @@ -9,7 +10,7 @@ beforeEach(() => { fn = new Function(stack, 'fn', { handler: 'index.handler', code: Code.fromInline('exports.handler = ${handler.toString()}'), - runtime: Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); }); diff --git a/packages/aws-cdk-lib/aws-lambda/test/function-hash.test.ts b/packages/aws-cdk-lib/aws-lambda/test/function-hash.test.ts index 9004a96e12e5f..0a6a20730aff9 100644 --- a/packages/aws-cdk-lib/aws-lambda/test/function-hash.test.ts +++ b/packages/aws-cdk-lib/aws-lambda/test/function-hash.test.ts @@ -6,6 +6,7 @@ import { App, CfnOutput, CfnResource, Stack } from '../../core'; import * as cxapi from '../../cx-api'; import * as lambda from '../lib'; import { calculateFunctionHash, trimFromStart, VERSION_LOCKED } from '../lib/function-hash'; +import { DEFAULT_UNITTEST_RUNTIME } from '../lib/helpers-internal'; describe('function hash', () => { describe('trimFromStart', () => { @@ -32,14 +33,14 @@ describe('function hash', () => { }); const stack1 = new Stack(app, 'Stack1'); const fn1 = new lambda.Function(stack1, 'MyFunction1', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'handler.zip')), handler: 'index.handler', }); const stack2 = new Stack(app, 'Stack2'); const fn2 = new lambda.Function(stack2, 'MyFunction1', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'handler.zip')), handler: 'index.handler', }); @@ -57,7 +58,7 @@ describe('function hash', () => { }); const stack1 = new Stack(app); const fn1 = new lambda.Function(stack1, 'MyFunction1', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'my-lambda-handler')), handler: 'index.handler', }); @@ -74,7 +75,7 @@ describe('function hash', () => { }); const stack1 = new Stack(app, 'Stack1'); const fn1 = new lambda.Function(stack1, 'MyFunction', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'my-lambda-handler')), handler: 'index.handler', environment: { @@ -84,7 +85,7 @@ describe('function hash', () => { const stack2 = new Stack(app); const fn2 = new lambda.Function(stack2, 'MyFunction', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'my-lambda-handler')), handler: 'index.handler', environment: { @@ -104,7 +105,7 @@ describe('function hash', () => { }); const stack1 = new Stack(app, 'Stack1'); const fn1 = new lambda.Function(stack1, 'MyFunction', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'my-lambda-handler')), handler: 'index.handler', environment: { @@ -114,7 +115,7 @@ describe('function hash', () => { const stack2 = new Stack(app); const fn2 = new lambda.Function(stack2, 'MyFunction', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'my-lambda-handler')), handler: 'index.handler', environment: { @@ -129,14 +130,14 @@ describe('function hash', () => { test('inline code change impacts the hash', () => { const stack1 = new Stack(); const fn1 = new lambda.Function(stack1, 'MyFunction', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('foo'), handler: 'index.handler', }); const stack2 = new Stack(); const fn2 = new lambda.Function(stack2, 'MyFunction', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('foo bar'), handler: 'index.handler', }); @@ -153,13 +154,13 @@ describe('function hash', () => { stack1 = new Stack(); layer1 = new lambda.LayerVersion(stack1, 'MyLayer', { code: lambda.Code.fromAsset(path.join(__dirname, 'layer-code')), - compatibleRuntimes: [lambda.Runtime.NODEJS_16_X], + compatibleRuntimes: [DEFAULT_UNITTEST_RUNTIME], license: 'Apache-2.0', description: 'A layer to test the L2 construct', }); layer2 = new lambda.LayerVersion(stack1, 'MyLayer2', { code: lambda.Code.fromAsset(path.join(__dirname, 'layer-code')), - compatibleRuntimes: [lambda.Runtime.NODEJS_16_X], + compatibleRuntimes: [DEFAULT_UNITTEST_RUNTIME], license: 'Apache-2.0', description: 'A layer to test the L2 construct', }); @@ -168,7 +169,7 @@ describe('function hash', () => { test('same configuration yields the same hash', () => { const stack2 = new Stack(); const fn1 = new lambda.Function(stack2, 'MyFunction', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('foo'), handler: 'index.handler', layers: [layer1], @@ -176,7 +177,7 @@ describe('function hash', () => { const stack3 = new Stack(); const fn2 = new lambda.Function(stack3, 'MyFunction', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('foo'), handler: 'index.handler', layers: [layer1], @@ -189,7 +190,7 @@ describe('function hash', () => { test('different layers impacts hash', () => { const stack2 = new Stack(); const fn1 = new lambda.Function(stack2, 'MyFunction', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('foo'), handler: 'index.handler', layers: [layer1], @@ -197,7 +198,7 @@ describe('function hash', () => { const stack3 = new Stack(); const fn2 = new lambda.Function(stack3, 'MyFunction', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('foo'), handler: 'index.handler', layers: [layer2], @@ -211,7 +212,7 @@ describe('function hash', () => { test('without feature flag, preserve old behavior to avoid unnecessary invalidation of templates', () => { const stack2 = new Stack(); const fn1 = new lambda.Function(stack2, 'MyFunction', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('foo'), handler: 'index.handler', layers: [layer1, layer2], @@ -219,7 +220,7 @@ describe('function hash', () => { const stack3 = new Stack(); const fn2 = new lambda.Function(stack3, 'MyFunction', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('foo'), handler: 'index.handler', layers: [layer2, layer1], @@ -234,7 +235,7 @@ describe('function hash', () => { const stack2 = new Stack(app, 'stack2'); const fn1 = new lambda.Function(stack2, 'MyFunction', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('foo'), handler: 'index.handler', layers: [layer1, layer2], @@ -242,7 +243,7 @@ describe('function hash', () => { const stack3 = new Stack(app, 'stack3'); const fn2 = new lambda.Function(stack3, 'MyFunction', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('foo'), handler: 'index.handler', layers: [layer2, layer1], @@ -258,7 +259,7 @@ describe('function hash', () => { const stack2 = new Stack(app, 'stack2'); const importedLayer1 = lambda.LayerVersion.fromLayerVersionArn(stack2, 'imported-layer', 'arn:aws:lambda:::layer::'); const fn1 = new lambda.Function(stack2, 'MyFunction', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('foo'), handler: 'index.handler', layers: [importedLayer1], @@ -267,7 +268,7 @@ describe('function hash', () => { const stack3 = new Stack(app, 'stack3'); const importedLayer2 = lambda.LayerVersion.fromLayerVersionArn(stack3, 'imported-layer', 'arn:aws:lambda:::layer::'); const fn2 = new lambda.Function(stack3, 'MyFunction', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('foo'), handler: 'index.handler', layers: [importedLayer2], @@ -281,7 +282,7 @@ describe('function hash', () => { test('without "currentVersion", we preserve old behavior to avoid unnecessary invalidation of templates', () => { const stack1 = new Stack(); const fn1 = new lambda.Function(stack1, 'MyFunction', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'my-lambda-handler')), handler: 'index.handler', environment: { @@ -292,7 +293,7 @@ describe('function hash', () => { const stack2 = new Stack(); const fn2 = new lambda.Function(stack2, 'MyFunction', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'my-lambda-handler')), handler: 'index.handler', environment: { @@ -307,7 +308,7 @@ describe('function hash', () => { test('with "currentVersion", we sort env keys so order is consistent', () => { const stack1 = new Stack(); const fn1 = new lambda.Function(stack1, 'MyFunction', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'my-lambda-handler')), handler: 'index.handler', environment: { @@ -320,7 +321,7 @@ describe('function hash', () => { const stack2 = new Stack(); const fn2 = new lambda.Function(stack2, 'MyFunction', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'my-lambda-handler')), handler: 'index.handler', environment: { @@ -349,14 +350,14 @@ describe('function hash', () => { test('DependsOn does not impact function hash', () => { const stack1 = new Stack(app, 'Stack1'); const fn1 = new lambda.Function(stack1, 'MyFunction1', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'handler.zip')), handler: 'index.handler', }); const stack2 = new Stack(app, 'Stack2'); const fn2 = new lambda.Function(stack2, 'MyFunction1', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'handler.zip')), handler: 'index.handler', }); @@ -375,14 +376,14 @@ describe('function hash', () => { test('properties not locked to the version do not impact function hash', () => { const stack1 = new Stack(app, 'Stack1'); const fn1 = new lambda.Function(stack1, 'MyFunction', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'handler.zip')), handler: 'index.handler', }); const stack2 = new Stack(app, 'Stack2'); const fn2 = new lambda.Function(stack2, 'MyFunction', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'handler.zip')), handler: 'index.handler', @@ -396,7 +397,7 @@ describe('function hash', () => { test('unclassified property throws an error', () => { const stack = new Stack(app); const fn1 = new lambda.Function(stack, 'MyFunction1', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'handler.zip')), handler: 'index.handler', }); @@ -408,7 +409,7 @@ describe('function hash', () => { test('manual classification as version locked', () => { const stack = new Stack(app); const fn1 = new lambda.Function(stack, 'MyFunction1', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'handler.zip')), handler: 'index.handler', }); @@ -422,7 +423,7 @@ describe('function hash', () => { test('manual classification as not version locked', () => { const stack = new Stack(app); const fn1 = new lambda.Function(stack, 'MyFunction1', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'handler.zip')), handler: 'index.handler', }); diff --git a/packages/aws-cdk-lib/aws-lambda/test/function-url.test.ts b/packages/aws-cdk-lib/aws-lambda/test/function-url.test.ts index 624a1769a94d2..e43cdf6e543ca 100644 --- a/packages/aws-cdk-lib/aws-lambda/test/function-url.test.ts +++ b/packages/aws-cdk-lib/aws-lambda/test/function-url.test.ts @@ -2,6 +2,7 @@ import { Template } from '../../assertions'; import * as iam from '../../aws-iam'; import * as cdk from '../../core'; import * as lambda from '../lib'; +import { DEFAULT_UNITTEST_RUNTIME } from '../lib/helpers-internal'; describe('FunctionUrl', () => { test('default function url', () => { @@ -10,7 +11,7 @@ describe('FunctionUrl', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); // WHEN @@ -36,7 +37,7 @@ describe('FunctionUrl', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); // WHEN @@ -94,7 +95,7 @@ describe('FunctionUrl', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const aliasName = 'prod'; const alias = new lambda.Alias(stack, 'Alias', { @@ -124,7 +125,7 @@ describe('FunctionUrl', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const version = new lambda.Version(stack, 'Version', { lambda: fn, @@ -146,7 +147,7 @@ describe('FunctionUrl', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); // WHEN @@ -169,7 +170,7 @@ describe('FunctionUrl', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const fnUrl = new lambda.FunctionUrl(stack, 'FunctionUrl', { function: fn, diff --git a/packages/aws-cdk-lib/aws-lambda/test/function.test.ts b/packages/aws-cdk-lib/aws-lambda/test/function.test.ts index 3bb544ade31e6..72d6c983d6d6f 100644 --- a/packages/aws-cdk-lib/aws-lambda/test/function.test.ts +++ b/packages/aws-cdk-lib/aws-lambda/test/function.test.ts @@ -19,6 +19,7 @@ import * as cxapi from '../../cx-api'; import * as lambda from '../lib'; import { AdotLambdaLayerJavaSdkVersion } from '../lib/adot-layers'; import { calculateFunctionHash } from '../lib/function-hash'; +import { DEFAULT_UNITTEST_RUNTIME } from '../lib/helpers-internal'; describe('function', () => { const dockerLambdaHandlerPath = path.join(__dirname, 'docker-lambda-handler'); @@ -28,7 +29,7 @@ describe('function', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); Template.fromStack(stack).hasResourceProperties('AWS::IAM::Role', { @@ -52,7 +53,7 @@ describe('function', () => { Code: { ZipFile: 'foo' }, Handler: 'index.handler', Role: { 'Fn::GetAtt': ['MyLambdaServiceRole4539ECB6', 'Arn'] }, - Runtime: 'nodejs16.x', + Runtime: 'nodejs99.x', }, DependsOn: ['MyLambdaServiceRole4539ECB6'], }); @@ -63,7 +64,7 @@ describe('function', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, initialPolicy: [new iam.PolicyStatement({ actions: ['*'], resources: ['*'] })], }); Template.fromStack(stack).hasResourceProperties('AWS::IAM::Role', { @@ -105,7 +106,7 @@ describe('function', () => { Code: { ZipFile: 'foo' }, Handler: 'index.handler', Role: { 'Fn::GetAtt': ['MyLambdaServiceRole4539ECB6', 'Arn'] }, - Runtime: 'nodejs16.x', + Runtime: 'nodejs99.x', }, DependsOn: ['MyLambdaServiceRoleDefaultPolicy5BBC6F68', 'MyLambdaServiceRole4539ECB6'], }); @@ -741,7 +742,7 @@ describe('function', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, functionName: 'OneFunctionToRuleThemAll', deadLetterQueueEnabled: true, }); @@ -809,7 +810,7 @@ describe('function', () => { 'Arn', ], }, - Runtime: 'nodejs16.x', + Runtime: 'nodejs99.x', DeadLetterConfig: { TargetArn: { 'Fn::GetAtt': [ @@ -833,7 +834,7 @@ describe('function', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, deadLetterQueueEnabled: true, }); @@ -859,7 +860,7 @@ describe('function', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, deadLetterQueueEnabled: false, }); @@ -874,7 +875,7 @@ describe('function', () => { 'Arn', ], }, - Runtime: 'nodejs16.x', + Runtime: 'nodejs99.x', }); }); @@ -889,7 +890,7 @@ describe('function', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, deadLetterQueue: dlQueue, }); @@ -934,7 +935,7 @@ describe('function', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, deadLetterQueueEnabled: true, deadLetterQueue: dlQueue, }); @@ -980,7 +981,7 @@ describe('function', () => { expect(() => new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, deadLetterQueueEnabled: false, deadLetterQueue: dlQueue, })).toThrow(/deadLetterQueue defined but deadLetterQueueEnabled explicitly set to false/); @@ -994,7 +995,7 @@ describe('function', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, deadLetterTopic: dlTopic, }); @@ -1029,7 +1030,7 @@ describe('function', () => { expect(() => new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, deadLetterQueueEnabled: false, deadLetterTopic: dlTopic, })).toThrow(/deadLetterQueue and deadLetterTopic cannot be specified together at the same time/); @@ -1043,7 +1044,7 @@ describe('function', () => { expect(() => new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, deadLetterQueueEnabled: true, deadLetterTopic: dlTopic, })).toThrow(/deadLetterQueue and deadLetterTopic cannot be specified together at the same time/); @@ -1058,7 +1059,7 @@ describe('function', () => { expect(() => new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, deadLetterQueue: dlQueue, deadLetterTopic: dlTopic, })).toThrow(/deadLetterQueue and deadLetterTopic cannot be specified together at the same time/); @@ -1070,7 +1071,7 @@ describe('function', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, tracing: lambda.Tracing.ACTIVE, }); @@ -1108,7 +1109,7 @@ describe('function', () => { 'Arn', ], }, - Runtime: 'nodejs16.x', + Runtime: 'nodejs99.x', TracingConfig: { Mode: 'Active', }, @@ -1126,7 +1127,7 @@ describe('function', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, tracing: lambda.Tracing.PASS_THROUGH, }); @@ -1164,7 +1165,7 @@ describe('function', () => { 'Arn', ], }, - Runtime: 'nodejs16.x', + Runtime: 'nodejs99.x', TracingConfig: { Mode: 'PassThrough', }, @@ -1182,7 +1183,7 @@ describe('function', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, tracing: lambda.Tracing.DISABLED, }); @@ -1200,7 +1201,7 @@ describe('function', () => { 'Arn', ], }, - Runtime: 'nodejs16.x', + Runtime: 'nodejs99.x', }, DependsOn: [ 'MyLambdaServiceRole4539ECB6', @@ -1234,7 +1235,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'Function', { code: lambda.Code.fromInline('xxx'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); // WHEN @@ -1264,7 +1265,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'Function', { code: lambda.Code.fromInline('xxx'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const service = new iam.ServicePrincipal('apigateway.amazonaws.com'); @@ -1290,7 +1291,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'Function', { code: lambda.Code.fromInline('xxx'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const account = new iam.AccountPrincipal('123456789012'); @@ -1316,7 +1317,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'Function', { code: lambda.Code.fromInline('xxx'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const account = new iam.ArnPrincipal('arn:aws:iam::123456789012:role/someRole'); @@ -1342,7 +1343,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'Function', { code: lambda.Code.fromInline('xxx'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const org = new iam.OrganizationPrincipal('my-org-id'); @@ -1369,7 +1370,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'Function', { code: lambda.Code.fromInline('xxx'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const service = new iam.ServicePrincipal('elasticloadbalancing.amazonaws.com'); @@ -1398,7 +1399,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'Function', { code: lambda.Code.fromInline('xxx'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); // WHEN @@ -1430,7 +1431,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'Function', { code: lambda.Code.fromInline('xxx'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); // WHEN @@ -1531,7 +1532,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'Function', { code: lambda.Code.fromInline('xxx'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); // THEN @@ -1550,7 +1551,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'Function', { code: lambda.Code.fromInline('xxx'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); let bindTarget; @@ -1575,7 +1576,7 @@ describe('function', () => { const code = new lambda.S3Code(bucket, 'ObjectKey'); const fn = new lambda.Function(stack, 'fn', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('exports.main = function() { console.log("DONE"); }'), handler: 'index.main', }); @@ -1585,7 +1586,7 @@ describe('function', () => { // WHEN const layer = new lambda.LayerVersion(stack, 'LayerVersion', { code, - compatibleRuntimes: [lambda.Runtime.NODEJS_16_X], + compatibleRuntimes: [DEFAULT_UNITTEST_RUNTIME], }); fn.addLayers(layer); @@ -1603,12 +1604,12 @@ describe('function', () => { const code = new lambda.S3Code(bucket, 'ObjectKey'); const layer = new lambda.LayerVersion(stack, 'LayerVersion', { code, - compatibleRuntimes: [lambda.Runtime.NODEJS_16_X], + compatibleRuntimes: [DEFAULT_UNITTEST_RUNTIME], }); // function with layer const fn = new lambda.Function(stack, 'fn', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('exports.main = function() { console.log("DONE"); }'), handler: 'index.main', layers: [layer], @@ -1636,16 +1637,16 @@ describe('function', () => { const stack = new cdk.Stack(undefined, 'TestStack'); const layer = lambda.LayerVersion.fromLayerVersionAttributes(stack, 'TestLayer', { layerVersionArn: 'arn:aws:...', - compatibleRuntimes: [lambda.Runtime.NODEJS_16_X], + compatibleRuntimes: [new lambda.Runtime('something2')], }); // THEN expect(() => new lambda.Function(stack, 'Function', { layers: [layer], - runtime: lambda.Runtime.NODEJS_18_X, + runtime: new lambda.Runtime('something1'), code: lambda.Code.fromInline('exports.main = function() { console.log("DONE"); }'), handler: 'index.main', - })).toThrow(/nodejs18.x is not in \[nodejs16.x\]/); + })).toThrow(/something1 is not in \[something2\]/); }); test('using more than 5 layers', () => { @@ -1653,13 +1654,13 @@ describe('function', () => { const stack = new cdk.Stack(undefined, 'TestStack'); const layers = new Array(6).fill(lambda.LayerVersion.fromLayerVersionAttributes(stack, 'TestLayer', { layerVersionArn: 'arn:aws:...', - compatibleRuntimes: [lambda.Runtime.NODEJS_16_X], + compatibleRuntimes: [DEFAULT_UNITTEST_RUNTIME], })); // THEN expect(() => new lambda.Function(stack, 'Function', { layers, - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('exports.main = function() { console.log("DONE"); }'), handler: 'index.main', })).toThrow(/Unable to add layer:/); @@ -1743,7 +1744,7 @@ describe('function', () => { // WHEN new lambda.Function(stack, 'fn', { code: lambda.Code.fromInline('boom'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.bam', events: [ new EventSource(), @@ -1819,7 +1820,7 @@ describe('function', () => { new lambda.Function(stack, 'fn', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, onFailure: { bind: () => ({ destination: 'on-failure-arn' }), }, @@ -1855,7 +1856,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'fn', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, maxEventAge: cdk.Duration.hours(1), }); @@ -1889,7 +1890,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'fn', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); // WHEN @@ -1918,7 +1919,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'fn', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); fn.addEnvironment('KEY', 'value', { removeInEdge: true }); @@ -1937,7 +1938,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'fn', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, environment: { KEY: 'value', }, @@ -2020,7 +2021,7 @@ describe('function', () => { // WHEN/THEN expect(() => new lambda.Function(stack, 'fn', { handler: 'foo', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline(''), })).toThrow(/Lambda inline code cannot be empty/); }); @@ -2029,7 +2030,7 @@ describe('function', () => { const stack = new cdk.Stack(); const fn = new lambda.Function(stack, 'fn', { handler: 'foo', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('foo'), }); const logGroup = fn.logGroup; @@ -2047,7 +2048,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'fn', { handler: 'foo', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('foo'), deadLetterQueue: dlQueue, }); @@ -2069,7 +2070,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'fn', { handler: 'foo', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('foo'), deadLetterTopic: dlTopic, }); @@ -2086,7 +2087,7 @@ describe('function', () => { const stack = new cdk.Stack(); const fn = new lambda.Function(stack, 'fn', { handler: 'foo', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('foo'), deadLetterQueueEnabled: true, }); @@ -2103,7 +2104,7 @@ describe('function', () => { const stack = new cdk.Stack(); const fn = new lambda.Function(stack, 'fn', { handler: 'foo', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('foo'), }); const deadLetterQueue = fn.deadLetterQueue; @@ -2117,7 +2118,7 @@ describe('function', () => { const stack = new cdk.Stack(); const fn = new lambda.Function(stack, 'fn', { handler: 'foo', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('foo'), logRetention: logs.RetentionDays.FIVE_DAYS, }); @@ -2144,7 +2145,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const version1 = fn.latestVersion; @@ -2172,7 +2173,7 @@ describe('function', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, environment: { SOME: 'Variable', }, @@ -2363,7 +2364,7 @@ describe('function', () => { expect(() => new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, profilingGroup: new ProfilingGroup(stack, 'ProfilingGroup'), environment: { AWS_CODEGURU_PROFILER_GROUP_ARN: 'profiler_group_arn', @@ -2381,7 +2382,7 @@ describe('function', () => { // WHEN const { timeout } = new lambda.Function(stack, 'MyFunction', { handler: 'foo', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'handler.zip')), timeout: cdk.Duration.minutes(2), }); @@ -2397,7 +2398,7 @@ describe('function', () => { // WHEN const { timeout } = new lambda.Function(stack, 'MyFunction', { handler: 'foo', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'handler.zip')), }); @@ -2413,7 +2414,7 @@ describe('function', () => { const stack1 = new cdk.Stack(); const fn1 = new lambda.Function(stack1, 'MyFunction', { handler: 'foo', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'handler.zip')), environment: { FOO: 'bar', @@ -2422,7 +2423,7 @@ describe('function', () => { const stack2 = new cdk.Stack(); const fn2 = new lambda.Function(stack2, 'MyFunction', { handler: 'foo', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'handler.zip')), environment: { FOO: 'bear', @@ -2466,7 +2467,7 @@ describe('function', () => { new lambda.Function(stack, 'MyFunction', { vpc, handler: 'foo', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'handler.zip')), filesystem: lambda.FileSystem.fromEfsAccessPoint(accessPoint, '/mnt/msg'), }); @@ -2521,7 +2522,7 @@ describe('function', () => { expect(() => { new lambda.Function(stack, 'MyFunction', { handler: 'foo', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'handler.zip')), filesystem: lambda.FileSystem.fromEfsAccessPoint(accessPoint, '/mnt/msg'), }); @@ -2549,7 +2550,7 @@ describe('function', () => { vpc, handler: 'foo', securityGroups: [securityGroup], - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'handler.zip')), filesystem: lambda.FileSystem.fromEfsAccessPoint(accessPoint, '/mnt/msg'), }); @@ -2713,7 +2714,7 @@ describe('function', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, codeSigningConfig, }); @@ -2747,7 +2748,7 @@ describe('function', () => { const stack = new cdk.Stack(); new lambda.Function(stack, 'MyFunction', { code: lambda.Code.fromInline('foo'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', architectures: [lambda.Architecture.ARM_64], @@ -2762,7 +2763,7 @@ describe('function', () => { const stack = new cdk.Stack(); new lambda.Function(stack, 'MyFunction', { code: lambda.Code.fromInline('foo'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', architecture: lambda.Architecture.ARM_64, @@ -2777,7 +2778,7 @@ describe('function', () => { const stack = new cdk.Stack(); expect(() => new lambda.Function(stack, 'MyFunction', { code: lambda.Code.fromInline('foo'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', architecture: lambda.Architecture.ARM_64, @@ -2789,7 +2790,7 @@ describe('function', () => { const stack = new cdk.Stack(); expect(() => new lambda.Function(stack, 'MyFunction', { code: lambda.Code.fromInline('foo'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', architectures: [lambda.Architecture.X86_64, lambda.Architecture.ARM_64], @@ -2800,7 +2801,7 @@ describe('function', () => { const stack = new cdk.Stack(); const fn = new lambda.Function(stack, 'MyFunction', { code: lambda.Code.fromInline('foo'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', architecture: lambda.Architecture.ARM_64, }); @@ -2811,7 +2812,7 @@ describe('function', () => { const stack = new cdk.Stack(); expect(() => new lambda.Function(stack, 'MyFunction', { code: lambda.Code.fromInline('foo'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', functionName: 'a'.repeat(65), })).toThrow(/Function name can not be longer than 64 characters/); @@ -2824,7 +2825,7 @@ describe('function', () => { new lambda.Function(stack, `foo${invalidChar}`, { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, functionName: `foo${invalidChar}`, }); }).toThrow(/can contain only letters, numbers, hyphens, or underscores with no spaces./); @@ -2840,7 +2841,7 @@ describe('function', () => { new lambda.Function(stack, 'foo', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, functionName: tokenizedFunctionName, }); }).not.toThrow(); @@ -2850,7 +2851,7 @@ describe('function', () => { const stack = new cdk.Stack(); expect(() => new lambda.Function(stack, 'MyFunction', { code: lambda.Code.fromInline('foo'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', description: 'a'.repeat(257), })).toThrow(/Function description can not be longer than 256 characters/); @@ -2865,7 +2866,7 @@ describe('function', () => { new lambda.Function(stack, 'foo', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, description: tokenizedFunctionDescription, }); }).not.toThrow(); @@ -2878,7 +2879,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); // WHEN @@ -2902,7 +2903,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); // WHEN @@ -2951,7 +2952,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); fn.addFunctionUrl(); @@ -3093,7 +3094,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'Function', { code: lambda.Code.fromInline('xxx'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const sourceArnA = 'some-arn-a'; const sourceArnB = 'some-arn-b'; @@ -3167,7 +3168,7 @@ describe('function', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, adotInstrumentation: { layerVersion: lambda.AdotLayerVersion.fromJavaSdkLayerVersion(AdotLambdaLayerJavaSdkVersion.V1_28_1), execWrapper: lambda.AdotLambdaExecWrapper.REGULAR_HANDLER, @@ -3254,7 +3255,7 @@ test('throws if ephemeral storage size is out of bound', () => { expect(() => new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'bar', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, ephemeralStorageSize: Size.mebibytes(511), })).toThrow(/Ephemeral storage size must be between 512 and 10240 MB/); }); @@ -3264,7 +3265,7 @@ test('set ephemeral storage to desired size', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'bar', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, ephemeralStorageSize: Size.mebibytes(1024), }); @@ -3273,7 +3274,7 @@ test('set ephemeral storage to desired size', () => { { Code: { ZipFile: 'foo' }, Handler: 'bar', - Runtime: 'nodejs16.x', + Runtime: 'nodejs99.x', EphemeralStorage: { Size: 1024, }, @@ -3287,7 +3288,7 @@ test('ephemeral storage allows unresolved tokens', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'bar', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, ephemeralStorageSize: Size.mebibytes(Lazy.number({ produce: () => 1024 })), }); }).not.toThrow(); @@ -3299,7 +3300,7 @@ test('FunctionVersionUpgrade adds new description to function', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'bar', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, description: 'my description', }); @@ -3310,7 +3311,7 @@ test('FunctionVersionUpgrade adds new description to function', () => { { Code: { ZipFile: 'foo' }, Handler: 'bar', - Runtime: 'nodejs16.x', + Runtime: 'nodejs99.x', Description: Match.stringLikeRegexp('my description version-hash'), }, }); @@ -3341,7 +3342,7 @@ test('test 2.87.0 version hash stability', () => { const layer = new lambda.LayerVersion(stack, 'MyLayer', { code: lambda.Code.fromAsset(path.join(__dirname, 'x.zip')), compatibleRuntimes: [ - lambda.Runtime.NODEJS_18_X, + DEFAULT_UNITTEST_RUNTIME, ], }); @@ -3354,7 +3355,7 @@ test('test 2.87.0 version hash stability', () => { }); const lambdaFn = new lambda.Function(stack, 'MyLambda', { - runtime: lambda.Runtime.NODEJS_18_X, + runtime: DEFAULT_UNITTEST_RUNTIME, memorySize: 128, handler: 'index.handler', timeout: cdk.Duration.seconds(30), diff --git a/packages/aws-cdk-lib/aws-lambda/test/lambda-insights.test.ts b/packages/aws-cdk-lib/aws-lambda/test/lambda-insights.test.ts index f35658b4079ba..424f3e1709bd3 100644 --- a/packages/aws-cdk-lib/aws-lambda/test/lambda-insights.test.ts +++ b/packages/aws-cdk-lib/aws-lambda/test/lambda-insights.test.ts @@ -17,7 +17,7 @@ function functionWithInsightsVersion( functionName: id, code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, architecture, insightsVersion, }); diff --git a/packages/aws-cdk-lib/aws-lambda/test/lambda-version.test.ts b/packages/aws-cdk-lib/aws-lambda/test/lambda-version.test.ts index 5feda7966771f..220da2737410a 100644 --- a/packages/aws-cdk-lib/aws-lambda/test/lambda-version.test.ts +++ b/packages/aws-cdk-lib/aws-lambda/test/lambda-version.test.ts @@ -2,6 +2,7 @@ import { testDeprecated } from '@aws-cdk/cdk-build-tools'; import { Template } from '../../assertions'; import * as cdk from '../../core'; import * as lambda from '../lib'; +import { DEFAULT_UNITTEST_RUNTIME } from '../lib/helpers-internal'; describe('lambda version', () => { test('can import a Lambda version by ARN', () => { @@ -31,7 +32,7 @@ describe('lambda version', () => { // GIVEN const stack = new cdk.Stack(); const fn = new lambda.Function(stack, 'Fn', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', code: lambda.Code.fromInline('foo'), }); @@ -63,7 +64,7 @@ describe('lambda version', () => { // GIVEN const stack = new cdk.Stack(); const fn = new lambda.Function(stack, 'Fn', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', code: lambda.Code.fromInline('foo'), }); @@ -108,7 +109,7 @@ describe('lambda version', () => { // GIVEN const stack = new cdk.Stack(); const fn = new lambda.Function(stack, 'Fn', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', code: lambda.Code.fromInline('foo'), }); @@ -136,7 +137,7 @@ describe('lambda version', () => { // GIVEN const stack = new cdk.Stack(); const fn = new lambda.Function(stack, 'Fn', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', code: lambda.Code.fromInline('foo'), }); @@ -160,7 +161,7 @@ describe('lambda version', () => { const app = new cdk.App(); const stack = new cdk.Stack(app, 'Stack'); const fn = new lambda.Function(stack, 'Fn', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', code: lambda.Code.fromInline('foo'), }); @@ -168,7 +169,7 @@ describe('lambda version', () => { // WHEN new lambda.Function(stack, 'OtherFn', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', code: lambda.Code.fromInline('foo'), environment: { @@ -189,7 +190,7 @@ describe('lambda version', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const version = new lambda.Version(stack, 'Version', { lambda: fn, diff --git a/packages/aws-cdk-lib/aws-lambda/test/layers.test.ts b/packages/aws-cdk-lib/aws-lambda/test/layers.test.ts index e4bc2ece6de9f..5d5bfb69716b8 100644 --- a/packages/aws-cdk-lib/aws-lambda/test/layers.test.ts +++ b/packages/aws-cdk-lib/aws-lambda/test/layers.test.ts @@ -4,6 +4,7 @@ import * as s3 from '../../aws-s3'; import * as cdk from '../../core'; import * as cxapi from '../../cx-api'; import * as lambda from '../lib'; +import { DEFAULT_UNITTEST_RUNTIME } from '../lib/helpers-internal'; describe('layers', () => { test('creating a layer', () => { @@ -15,7 +16,7 @@ describe('layers', () => { // WHEN new lambda.LayerVersion(stack, 'LayerVersion', { code, - compatibleRuntimes: [lambda.Runtime.NODEJS_16_X], + compatibleRuntimes: [DEFAULT_UNITTEST_RUNTIME], }); // THEN @@ -24,7 +25,7 @@ describe('layers', () => { S3Bucket: stack.resolve(bucket.bucketName), S3Key: 'ObjectKey', }, - CompatibleRuntimes: ['nodejs16.x'], + CompatibleRuntimes: ['nodejs99.x'], }); }); @@ -35,7 +36,7 @@ describe('layers', () => { const code = new lambda.S3Code(bucket, 'ObjectKey'); const layer = new lambda.LayerVersion(stack, 'LayerVersion', { code, - compatibleRuntimes: [lambda.Runtime.NODEJS_16_X], + compatibleRuntimes: [DEFAULT_UNITTEST_RUNTIME], }); // WHEN diff --git a/packages/aws-cdk-lib/aws-lambda/test/singleton-lambda.test.ts b/packages/aws-cdk-lib/aws-lambda/test/singleton-lambda.test.ts index 93d197053555f..8c0fea611fd5a 100644 --- a/packages/aws-cdk-lib/aws-lambda/test/singleton-lambda.test.ts +++ b/packages/aws-cdk-lib/aws-lambda/test/singleton-lambda.test.ts @@ -5,6 +5,7 @@ import * as iam from '../../aws-iam'; import * as s3 from '../../aws-s3'; import * as cdk from '../../core'; import * as lambda from '../lib'; +import { DEFAULT_UNITTEST_RUNTIME } from '../lib/helpers-internal'; describe('singleton lambda', () => { test('can add same singleton Lambda multiple times, only instantiated once in template', () => { @@ -248,7 +249,7 @@ describe('singleton lambda', () => { const singleton = new lambda.SingletonFunction(stack, 'Singleton', { uuid: '84c0de93-353f-4217-9b0b-45b6c993251a', code: new lambda.InlineCode('foo'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', }); @@ -276,7 +277,7 @@ describe('singleton lambda', () => { const singleton = new lambda.SingletonFunction(stack, 'Singleton', { uuid: '84c0de93-353f-4217-9b0b-45b6c993251a', code: new lambda.InlineCode('foo'), - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', securityGroups: [securityGroup], vpc: vpc, diff --git a/packages/aws-cdk-lib/aws-lambda/test/vpc-lambda.test.ts b/packages/aws-cdk-lib/aws-lambda/test/vpc-lambda.test.ts index cc12cf96b3c8e..aea49e172daaf 100644 --- a/packages/aws-cdk-lib/aws-lambda/test/vpc-lambda.test.ts +++ b/packages/aws-cdk-lib/aws-lambda/test/vpc-lambda.test.ts @@ -3,6 +3,7 @@ import { Template } from '../../assertions'; import * as ec2 from '../../aws-ec2'; import * as cdk from '../../core'; import * as lambda from '../lib'; +import { DEFAULT_UNITTEST_RUNTIME } from '../lib/helpers-internal'; describe('lambda + vpc', () => { describe('lambda in vpc', () => { @@ -21,7 +22,7 @@ describe('lambda + vpc', () => { fn = new lambda.Function(stack, 'Lambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, vpc: vpc, allowAllOutbound: false, }); @@ -47,7 +48,7 @@ describe('lambda + vpc', () => { new lambda.Function(stack, 'LambdaWithCustomSG', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, vpc, securityGroup: new ec2.SecurityGroup(stack, 'CustomSecurityGroupX', { vpc }), }); @@ -70,7 +71,7 @@ describe('lambda + vpc', () => { new lambda.Function(stack, 'LambdaWithCustomSGList', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, vpc, securityGroups: [ new ec2.SecurityGroup(stack, 'CustomSecurityGroupA', { vpc }), @@ -98,7 +99,7 @@ describe('lambda + vpc', () => { new lambda.Function(stack, 'LambdaWithWrongProps', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, vpc, securityGroup: new ec2.SecurityGroup(stack, 'CustomSecurityGroupB', { vpc }), securityGroups: [ @@ -189,7 +190,7 @@ describe('lambda + vpc', () => { const lambdaFn = new lambda.Function(stack, 'Lambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); // WHEN @@ -208,7 +209,7 @@ describe('lambda + vpc', () => { allowPublicSubnet: true, code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, vpc, vpcSubnets: { subnetType: ec2.SubnetType.PUBLIC }, }); @@ -236,7 +237,7 @@ describe('lambda + vpc', () => { new lambda.Function(stack, 'PrivateLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, vpc, vpcSubnets: { subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS }, }); @@ -272,7 +273,7 @@ describe('lambda + vpc', () => { new lambda.Function(stack, 'IsolatedLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, vpc, vpcSubnets: { subnetType: ec2.SubnetType.PRIVATE_ISOLATED }, }); @@ -317,7 +318,7 @@ describe('lambda + vpc', () => { new lambda.Function(stack, 'PublicLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, vpc, vpcSubnets: { subnetType: ec2.SubnetType.PUBLIC }, }); @@ -333,7 +334,7 @@ describe('lambda + vpc', () => { new lambda.Function(stack, 'Function', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, vpcSubnets: { subnetType: ec2.SubnetType.PRIVATE }, }); }).toThrow('Cannot configure \'vpcSubnets\' without configuring a VPC'); diff --git a/packages/aws-cdk-lib/aws-logs-destinations/test/lambda.test.ts b/packages/aws-cdk-lib/aws-logs-destinations/test/lambda.test.ts index da7e1baa38f56..91d592263d73c 100644 --- a/packages/aws-cdk-lib/aws-logs-destinations/test/lambda.test.ts +++ b/packages/aws-cdk-lib/aws-logs-destinations/test/lambda.test.ts @@ -1,5 +1,6 @@ import { Template } from '../../assertions'; import * as lambda from '../../aws-lambda'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; import * as logs from '../../aws-logs'; import * as cdk from '../../core'; import * as dests from '../lib'; @@ -14,7 +15,7 @@ beforeEach(() => { fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); logGroup = new logs.LogGroup(stack, 'LogGroup'); }); diff --git a/packages/aws-cdk-lib/aws-rds/test/instance.test.ts b/packages/aws-cdk-lib/aws-rds/test/instance.test.ts index 21cd60735ceec..a66e0b17ed859 100644 --- a/packages/aws-cdk-lib/aws-rds/test/instance.test.ts +++ b/packages/aws-cdk-lib/aws-rds/test/instance.test.ts @@ -4,6 +4,7 @@ import * as targets from '../../aws-events-targets'; import { ManagedPolicy, Role, ServicePrincipal, AccountPrincipal } from '../../aws-iam'; import * as kms from '../../aws-kms'; import * as lambda from '../../aws-lambda'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; import * as logs from '../../aws-logs'; import * as s3 from '../../aws-s3'; import * as cdk from '../../core'; @@ -531,7 +532,7 @@ describe('instance', () => { const fn = new lambda.Function(stack, 'Function', { code: lambda.Code.fromInline('dummy'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); // WHEN diff --git a/packages/aws-cdk-lib/aws-s3-deployment/test/content.test.ts b/packages/aws-cdk-lib/aws-s3-deployment/test/content.test.ts index 138624d5b57f0..8fcfbc1292a35 100644 --- a/packages/aws-cdk-lib/aws-s3-deployment/test/content.test.ts +++ b/packages/aws-cdk-lib/aws-s3-deployment/test/content.test.ts @@ -1,4 +1,5 @@ import * as lambda from '../../aws-lambda'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; import * as s3 from '../../aws-s3'; import { Lazy, Stack } from '../../core'; import { Source } from '../lib'; @@ -84,7 +85,7 @@ test('json-encoded string', () => { test('markers are returned in the source config', () => { const stack = new Stack(); - const handler = new lambda.Function(stack, 'Handler', { runtime: lambda.Runtime.NODEJS_16_X, code: lambda.Code.fromInline('foo'), handler: 'index.handler' }); + const handler = new lambda.Function(stack, 'Handler', { runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('foo'), handler: 'index.handler' }); const actual = Source.data('file1.txt', `boom-${stack.account}`).bind(stack, { handlerRole: handler.role! }); expect(actual.markers).toStrictEqual({ '<>': { Ref: 'AWS::AccountId' }, diff --git a/packages/aws-cdk-lib/aws-s3-notifications/test/lambda/lambda.test.ts b/packages/aws-cdk-lib/aws-s3-notifications/test/lambda/lambda.test.ts index 2cd403a6b619a..aca061dbb4ee1 100644 --- a/packages/aws-cdk-lib/aws-s3-notifications/test/lambda/lambda.test.ts +++ b/packages/aws-cdk-lib/aws-s3-notifications/test/lambda/lambda.test.ts @@ -1,5 +1,6 @@ import { Match, Template } from '../../../assertions'; import * as lambda from '../../../aws-lambda'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../../aws-lambda/lib/helpers-internal'; import * as s3 from '../../../aws-s3'; import { Stack, App } from '../../../core'; import * as s3n from '../../lib'; @@ -9,13 +10,13 @@ test('add notifications to multiple functions', () => { const stack = new Stack(); const bucket = new s3.Bucket(stack, 'MyBucket'); const fn1 = new lambda.Function(stack, 'MyFunction1', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', code: lambda.Code.fromInline('foo'), }); const fn2 = new lambda.Function(stack, 'MyFunction2', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', code: lambda.Code.fromInline('foo'), }); @@ -80,7 +81,7 @@ test('lambda in a different stack as notification target', () => { const lambdaFunction = new lambda.Function(lambdaStack, 'lambdaFunction', { code: lambda.Code.fromInline('whatever'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); const bucket = new s3.Bucket(bucketStack, 'bucket'); @@ -121,7 +122,7 @@ test('lambda as notification target', () => { const stack = new Stack(); const bucketA = new s3.Bucket(stack, 'MyBucket'); const fn = new lambda.Function(stack, 'MyFunction', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', code: lambda.Code.fromInline('foo'), }); @@ -188,7 +189,7 @@ test('permissions are added as a dependency to the notifications resource when u const bucket = new s3.Bucket(stack, 'MyBucket'); const fn = new lambda.SingletonFunction(stack, 'MyFunction', { uuid: 'uuid', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', code: lambda.Code.fromInline('foo'), }); @@ -208,7 +209,7 @@ test('add multiple event notifications using a singleton function', () => { const bucket = new s3.Bucket(stack, 'MyBucket'); const fn = new lambda.SingletonFunction(stack, 'MyFunction', { uuid: 'uuid', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', code: lambda.Code.fromInline('foo'), }); diff --git a/packages/aws-cdk-lib/aws-secretsmanager/test/rotation-schedule.test.ts b/packages/aws-cdk-lib/aws-secretsmanager/test/rotation-schedule.test.ts index 912052de279c0..5ae60c2356190 100644 --- a/packages/aws-cdk-lib/aws-secretsmanager/test/rotation-schedule.test.ts +++ b/packages/aws-cdk-lib/aws-secretsmanager/test/rotation-schedule.test.ts @@ -2,6 +2,7 @@ import { Match, Template } from '../../assertions'; import * as ec2 from '../../aws-ec2'; import * as kms from '../../aws-kms'; import * as lambda from '../../aws-lambda'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; import * as cdk from '../../core'; import { Duration } from '../../core'; import * as secretsmanager from '../lib'; @@ -15,7 +16,7 @@ test('create a rotation schedule with a rotation Lambda', () => { // GIVEN const secret = new secretsmanager.Secret(stack, 'Secret'); const rotationLambda = new lambda.Function(stack, 'Lambda', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('export.handler = event => event;'), handler: 'index.handler', }); @@ -47,7 +48,7 @@ test('create a rotation schedule without immediate rotation', () => { // GIVEN const secret = new secretsmanager.Secret(stack, 'Secret'); const rotationLambda = new lambda.Function(stack, 'Lambda', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('export.handler = event => event;'), handler: 'index.handler', }); @@ -75,7 +76,7 @@ test('assign permissions for rotation schedule with a rotation Lambda', () => { // GIVEN const secret = new secretsmanager.Secret(stack, 'Secret'); const rotationLambda = new lambda.Function(stack, 'Lambda', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('export.handler = event => event;'), handler: 'index.handler', }); @@ -134,7 +135,7 @@ test('grants correct permissions for secret imported by name', () => { // GIVEN const secret = secretsmanager.Secret.fromSecretNameV2(stack, 'Secret', 'mySecretName'); const rotationLambda = new lambda.Function(stack, 'Lambda', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('export.handler = event => event;'), handler: 'index.handler', }); @@ -186,7 +187,7 @@ test('assign kms permissions for rotation schedule with a rotation Lambda', () = const encryptionKey = new kms.Key(stack, 'Key'); const secret = new secretsmanager.Secret(stack, 'Secret', { encryptionKey }); const rotationLambda = new lambda.Function(stack, 'Lambda', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('export.handler = event => event;'), handler: 'index.handler', }); @@ -598,7 +599,7 @@ describe('manual rotations', () => { const localStack = new cdk.Stack(); const secret = new secretsmanager.Secret(localStack, 'Secret'); const rotationLambda = new lambda.Function(localStack, 'Lambda', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('export.handler = event => event;'), handler: 'index.handler', }); diff --git a/packages/aws-cdk-lib/aws-secretsmanager/test/secret.test.ts b/packages/aws-cdk-lib/aws-secretsmanager/test/secret.test.ts index 4b08ec69392bb..bf917381cb90e 100644 --- a/packages/aws-cdk-lib/aws-secretsmanager/test/secret.test.ts +++ b/packages/aws-cdk-lib/aws-secretsmanager/test/secret.test.ts @@ -5,6 +5,7 @@ import * as kms from '../../aws-kms'; import * as lambda from '../../aws-lambda'; import * as cdk from '../../core'; import * as secretsmanager from '../lib'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; let app: cdk.App; let stack: cdk.Stack; @@ -1177,7 +1178,7 @@ test('add a rotation schedule to an attached secret', () => { }), }); const rotationLambda = new lambda.Function(stack, 'Lambda', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('export.handler = event => event;'), handler: 'index.handler', }); diff --git a/packages/aws-cdk-lib/aws-ses-actions/test/actions.test.ts b/packages/aws-cdk-lib/aws-ses-actions/test/actions.test.ts index 0cfbb90a3c935..85d4b65786b17 100644 --- a/packages/aws-cdk-lib/aws-ses-actions/test/actions.test.ts +++ b/packages/aws-cdk-lib/aws-ses-actions/test/actions.test.ts @@ -85,7 +85,7 @@ test('add lambda action', () => { const fn = new lambda.Function(stack, 'Function', { code: lambda.Code.fromInline('boom'), handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); rule.addAction(new actions.Lambda({ diff --git a/packages/aws-cdk-lib/aws-sns-subscriptions/test/subs.test.ts b/packages/aws-cdk-lib/aws-sns-subscriptions/test/subs.test.ts index 6600bfb3f3a5e..585c3343ab899 100644 --- a/packages/aws-cdk-lib/aws-sns-subscriptions/test/subs.test.ts +++ b/packages/aws-cdk-lib/aws-sns-subscriptions/test/subs.test.ts @@ -1,6 +1,7 @@ import { Template } from '../../assertions'; import * as kms from '../../aws-kms'; import * as lambda from '../../aws-lambda'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; import * as sns from '../../aws-sns'; import * as sqs from '../../aws-sqs'; import { App, CfnParameter, Duration, RemovalPolicy, Stack, Token } from '../../core'; @@ -1235,7 +1236,7 @@ test('importing SQS queue and specify this as subscription', () => { test('lambda subscription', () => { const func = new lambda.Function(stack, 'MyFunc', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', code: lambda.Code.fromInline('exports.handler = function(e, c, cb) { return cb() }'), }); @@ -1295,7 +1296,7 @@ test('lambda subscription', () => { 'Arn', ], }, - 'Runtime': 'nodejs16.x', + 'Runtime': 'nodejs99.x', }, 'DependsOn': [ 'MyFuncServiceRole54065130', @@ -1346,7 +1347,7 @@ test('lambda subscription, cross region env agnostic', () => { displayName: 'displayName', }); const func = new lambda.Function(lambdaStack, 'MyFunc', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', code: lambda.Code.fromInline('exports.handler = function(e, c, cb) { return cb() }'), }); @@ -1399,7 +1400,7 @@ test('lambda subscription, cross region env agnostic', () => { ], }, 'Handler': 'index.handler', - 'Runtime': 'nodejs16.x', + 'Runtime': 'nodejs99.x', }, 'DependsOn': [ 'MyFuncServiceRole54065130', @@ -1460,7 +1461,7 @@ test('lambda subscription, cross region', () => { displayName: 'displayName', }); const func = new lambda.Function(lambdaStack, 'MyFunc', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', code: lambda.Code.fromInline('exports.handler = function(e, c, cb) { return cb() }'), }); @@ -1513,7 +1514,7 @@ test('lambda subscription, cross region', () => { ], }, 'Handler': 'index.handler', - 'Runtime': 'nodejs16.x', + 'Runtime': 'nodejs99.x', }, 'DependsOn': [ 'MyFuncServiceRole54065130', @@ -1746,7 +1747,7 @@ test('email and url subscriptions with unresolved - four subscriptions', () => { test('multiple subscriptions', () => { const queue = new sqs.Queue(stack, 'MyQueue'); const func = new lambda.Function(stack, 'MyFunc', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', code: lambda.Code.fromInline('exports.handler = function(e, c, cb) { return cb() }'), }); @@ -1862,7 +1863,7 @@ test('multiple subscriptions', () => { 'Arn', ], }, - 'Runtime': 'nodejs16.x', + 'Runtime': 'nodejs99.x', }, 'DependsOn': [ 'MyFuncServiceRole54065130', @@ -1914,7 +1915,7 @@ test('throws with mutliple subscriptions of the same subscriber', () => { test('with filter policy', () => { const func = new lambda.Function(stack, 'MyFunc', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', code: lambda.Code.fromInline('exports.handler = function(e, c, cb) { return cb() }'), }); @@ -1969,7 +1970,7 @@ test('with filter policy', () => { test('with filter policy scope MessageBody', () => { const func = new lambda.Function(stack, 'MyFunc', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', code: lambda.Code.fromInline('exports.handler = function(e, c, cb) { return cb() }'), }); @@ -2040,7 +2041,7 @@ test('region property on an imported topic as a parameter - sqs', () => { test('region property is present on an imported topic - lambda', () => { const imported = sns.Topic.fromTopicArn(stack, 'mytopic', 'arn:aws:sns:us-east-1:1234567890:mytopic'); const func = new lambda.Function(stack, 'MyFunc', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', code: lambda.Code.fromInline('exports.handler = function(e, c, cb) { return cb() }'), }); @@ -2055,7 +2056,7 @@ test('region property on an imported topic as a parameter - lambda', () => { const topicArn = new CfnParameter(stack, 'topicArn'); const imported = sns.Topic.fromTopicArn(stack, 'mytopic', topicArn.valueAsString); const func = new lambda.Function(stack, 'MyFunc', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', code: lambda.Code.fromInline('exports.handler = function(e, c, cb) { return cb() }'), }); diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/lambda/invoke.test.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/lambda/invoke.test.ts index 0b40caa859c05..9789dbb68229f 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/lambda/invoke.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/lambda/invoke.test.ts @@ -3,6 +3,7 @@ import * as lambda from '../../../aws-lambda'; import * as sfn from '../../../aws-stepfunctions'; import { Stack } from '../../../core'; import { LambdaInvocationType, LambdaInvoke } from '../../lib'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../../aws-lambda/lib/helpers-internal'; /* eslint-disable quote-props */ @@ -17,7 +18,7 @@ describe('LambdaInvoke', () => { lambdaFunction = new lambda.Function(stack, 'Fn', { code: lambda.Code.fromInline('foo'), handler: 'handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); }); diff --git a/packages/aws-cdk-lib/core/test/custom-resource-provider/custom-resource-provider.test.ts b/packages/aws-cdk-lib/core/test/custom-resource-provider/custom-resource-provider.test.ts index 18f197479bac9..f07d9e3c107e7 100644 --- a/packages/aws-cdk-lib/core/test/custom-resource-provider/custom-resource-provider.test.ts +++ b/packages/aws-cdk-lib/core/test/custom-resource-provider/custom-resource-provider.test.ts @@ -6,6 +6,7 @@ import { CUSTOMIZE_ROLES_CONTEXT_KEY } from '../../lib/helpers-internal'; import { toCloudFormation } from '../util'; const TEST_HANDLER = `${__dirname}/mock-provider`; +const STANDARD_PROVIDER = CustomResourceProviderRuntime.NODEJS_16_X; describe('custom resource provider', () => { describe('customize roles', () => { @@ -26,7 +27,7 @@ describe('custom resource provider', () => { // WHEN const cr = CustomResourceProvider.getOrCreateProvider(stack, 'Custom:MyResourceType', { codeDirectory: TEST_HANDLER, - runtime: CustomResourceProviderRuntime.NODEJS_16_X, + runtime: STANDARD_PROVIDER, }); cr.addToRolePolicy({ Action: 's3:GetBucket', @@ -103,7 +104,7 @@ describe('custom resource provider', () => { // WHEN const cr = CustomResourceProvider.getOrCreateProvider(stack, 'Custom:MyResourceType', { codeDirectory: TEST_HANDLER, - runtime: CustomResourceProviderRuntime.NODEJS_16_X, + runtime: STANDARD_PROVIDER, }); cr.addToRolePolicy({ Action: 's3:GetBucket', @@ -164,7 +165,7 @@ describe('custom resource provider', () => { // WHEN CustomResourceProvider.getOrCreate(stack, 'Custom:MyResourceType', { codeDirectory: TEST_HANDLER, - runtime: CustomResourceProviderRuntime.NODEJS_16_X, + runtime: STANDARD_PROVIDER, }); // THEN @@ -284,7 +285,7 @@ describe('custom resource provider', () => { // WHEN CustomResourceProvider.getOrCreate(stack, 'Custom:MyResourceType', { codeDirectory: TEST_HANDLER, - runtime: CustomResourceProviderRuntime.NODEJS_16_X, + runtime: STANDARD_PROVIDER, }); // Then @@ -326,7 +327,7 @@ describe('custom resource provider', () => { // WHEN CustomResourceProvider.getOrCreate(stack, 'Custom:MyResourceType', { codeDirectory: TEST_HANDLER, - runtime: CustomResourceProviderRuntime.NODEJS_16_X, + runtime: STANDARD_PROVIDER, }); // THEN -- no exception @@ -343,7 +344,7 @@ describe('custom resource provider', () => { // WHEN CustomResourceProvider.getOrCreate(stack, 'Custom:MyResourceType', { codeDirectory: TEST_HANDLER, - runtime: CustomResourceProviderRuntime.NODEJS_16_X, + runtime: STANDARD_PROVIDER, policyStatements: [ { statement1: 123 }, { statement2: { foo: 111 } }, @@ -370,7 +371,7 @@ describe('custom resource provider', () => { // WHEN const provider = CustomResourceProvider.getOrCreateProvider(stack, 'Custom:MyResourceType', { codeDirectory: TEST_HANDLER, - runtime: CustomResourceProviderRuntime.NODEJS_16_X, + runtime: STANDARD_PROVIDER, policyStatements: [ { statement1: 123 }, { statement2: { foo: 111 } }, @@ -397,7 +398,7 @@ describe('custom resource provider', () => { // WHEN CustomResourceProvider.getOrCreate(stack, 'Custom:MyResourceType', { codeDirectory: TEST_HANDLER, - runtime: CustomResourceProviderRuntime.NODEJS_16_X, + runtime: STANDARD_PROVIDER, memorySize: Size.gibibytes(2), timeout: Duration.minutes(5), description: 'veni vidi vici', @@ -419,7 +420,7 @@ describe('custom resource provider', () => { // WHEN CustomResourceProvider.getOrCreate(stack, 'Custom:MyResourceType', { codeDirectory: TEST_HANDLER, - runtime: CustomResourceProviderRuntime.NODEJS_16_X, + runtime: STANDARD_PROVIDER, environment: { B: 'b', A: 'a', @@ -445,7 +446,7 @@ describe('custom resource provider', () => { // WHEN const cr = CustomResourceProvider.getOrCreateProvider(stack, 'Custom:MyResourceType', { codeDirectory: TEST_HANDLER, - runtime: CustomResourceProviderRuntime.NODEJS_16_X, + runtime: STANDARD_PROVIDER, }); // THEN diff --git a/packages/aws-cdk-lib/custom-resources/test/provider-framework/provider.test.ts b/packages/aws-cdk-lib/custom-resources/test/provider-framework/provider.test.ts index 16176d6285588..fb9aa99f4dcfc 100644 --- a/packages/aws-cdk-lib/custom-resources/test/provider-framework/provider.test.ts +++ b/packages/aws-cdk-lib/custom-resources/test/provider-framework/provider.test.ts @@ -8,6 +8,7 @@ import * as logs from '../../../aws-logs'; import { Duration, Stack } from '../../../core'; import * as cr from '../../lib'; import * as util from '../../lib/provider-framework/util'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../../aws-lambda/lib/helpers-internal'; test('security groups are applied to all framework functions', () => { @@ -22,12 +23,12 @@ test('security groups are applied to all framework functions', () => { onEventHandler: new lambda.Function(stack, 'OnEvent', { code: lambda.Code.fromInline('foo'), handler: 'index.onEvent', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }), isCompleteHandler: new lambda.Function(stack, 'IsComplete', { code: lambda.Code.fromInline('foo'), handler: 'index.isComplete', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }), vpc: vpc, vpcSubnets: { subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS }, @@ -90,12 +91,12 @@ test('vpc is applied to all framework functions', () => { onEventHandler: new lambda.Function(stack, 'OnEvent', { code: lambda.Code.fromInline('foo'), handler: 'index.onEvent', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }), isCompleteHandler: new lambda.Function(stack, 'IsComplete', { code: lambda.Code.fromInline('foo'), handler: 'index.isComplete', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }), vpc: vpc, vpcSubnets: { subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS }, @@ -142,7 +143,7 @@ test('minimal setup', () => { onEventHandler: new lambda.Function(stack, 'MyHandler', { code: lambda.Code.fromAsset(path.join(__dirname, './integration-test-fixtures/s3-file-handler')), handler: 'index.onEvent', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }), }); @@ -174,7 +175,7 @@ test('if isComplete is specified, the isComplete framework handler is also inclu const handler = new lambda.Function(stack, 'MyHandler', { code: lambda.Code.fromAsset(path.join(__dirname, './integration-test-fixtures/s3-file-handler')), handler: 'index.onEvent', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); // WHEN @@ -248,7 +249,7 @@ test('fails if "queryInterval" and/or "totalTimeout" are set without "isComplete const handler = new lambda.Function(stack, 'MyHandler', { code: lambda.Code.fromAsset(path.join(__dirname, './integration-test-fixtures/s3-file-handler')), handler: 'index.onEvent', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }); // THEN @@ -304,7 +305,7 @@ describe('log retention', () => { onEventHandler: new lambda.Function(stack, 'MyHandler', { code: lambda.Code.fromAsset(path.join(__dirname, './integration-test-fixtures/s3-file-handler')), handler: 'index.onEvent', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }), logRetention: logs.RetentionDays.ONE_WEEK, }); @@ -335,7 +336,7 @@ describe('log retention', () => { onEventHandler: new lambda.Function(stack, 'MyHandler', { code: lambda.Code.fromAsset(path.join(__dirname, './integration-test-fixtures/s3-file-handler')), handler: 'index.onEvent', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }), }); @@ -354,7 +355,7 @@ describe('role', () => { onEventHandler: new lambda.Function(stack, 'MyHandler', { code: lambda.Code.fromAsset(path.join(__dirname, './integration-test-fixtures/s3-file-handler')), handler: 'index.onEvent', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }), role: new iam.Role(stack, 'MyRole', { assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'), @@ -382,7 +383,7 @@ describe('role', () => { onEventHandler: new lambda.Function(stack, 'MyHandler', { code: lambda.Code.fromAsset(path.join(__dirname, './integration-test-fixtures/s3-file-handler')), handler: 'index.onEvent', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }), }); @@ -409,7 +410,7 @@ describe('name', () => { onEventHandler: new lambda.Function(stack, 'MyHandler', { code: lambda.Code.fromAsset(path.join(__dirname, './integration-test-fixtures/s3-file-handler')), handler: 'index.onEvent', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }), providerFunctionName, }); @@ -434,7 +435,7 @@ describe('environment encryption', () => { onEventHandler: new lambda.Function(stack, 'MyHandler', { code: lambda.Code.fromAsset(path.join(__dirname, './integration-test-fixtures/s3-file-handler')), handler: 'index.onEvent', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, }), providerFunctionEnvEncryption: key, }); diff --git a/packages/aws-cdk-lib/custom-resources/test/provider-framework/waiter-state-machine.test.ts b/packages/aws-cdk-lib/custom-resources/test/provider-framework/waiter-state-machine.test.ts index 9d7fe2245c019..3a413db61afd9 100644 --- a/packages/aws-cdk-lib/custom-resources/test/provider-framework/waiter-state-machine.test.ts +++ b/packages/aws-cdk-lib/custom-resources/test/provider-framework/waiter-state-machine.test.ts @@ -3,6 +3,7 @@ import { Template } from '../../../assertions'; import { Code, Function as lambdaFn, Runtime } from '../../../aws-lambda'; import { Duration, Stack } from '../../../core'; import { WaiterStateMachine } from '../../lib/provider-framework/waiter-state-machine'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../../aws-lambda/lib/helpers-internal'; describe('state machine', () => { test('contains the needed resources', () => { @@ -12,12 +13,12 @@ describe('state machine', () => { const isCompleteHandler = new lambdaFn(stack, 'isComplete', { code: Code.fromInline('foo'), - runtime: Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', }); const timeoutHandler = new lambdaFn(stack, 'isTimeout', { code: Code.fromInline('foo'), - runtime: Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, handler: 'index.handler', }); const interval = Duration.hours(2); diff --git a/packages/aws-cdk-lib/package.json b/packages/aws-cdk-lib/package.json index d889036470f82..63179e2ba0d92 100644 --- a/packages/aws-cdk-lib/package.json +++ b/packages/aws-cdk-lib/package.json @@ -363,6 +363,7 @@ "./aws-kms": "./aws-kms/index.js", "./aws-lakeformation": "./aws-lakeformation/index.js", "./aws-lambda": "./aws-lambda/index.js", + "./aws-lambda/lib/helpers-internal": "./aws-lambda/lib/helpers-internal/index.js", "./aws-lambda-destinations": "./aws-lambda-destinations/index.js", "./aws-lambda-event-sources": "./aws-lambda-event-sources/index.js", "./aws-lambda-nodejs": "./aws-lambda-nodejs/index.js", diff --git a/packages/aws-cdk-lib/triggers/test/triggers.test.ts b/packages/aws-cdk-lib/triggers/test/triggers.test.ts index a1fd49dce17ba..f80259c9ee27a 100644 --- a/packages/aws-cdk-lib/triggers/test/triggers.test.ts +++ b/packages/aws-cdk-lib/triggers/test/triggers.test.ts @@ -1,5 +1,6 @@ import { Template } from '../../assertions'; import * as lambda from '../../aws-lambda'; +import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; import * as sns from '../../aws-sns'; import { Duration, Stack } from '../../core'; import * as triggers from '../lib'; @@ -11,7 +12,7 @@ test('minimal trigger function', () => { // WHEN new triggers.TriggerFunction(stack, 'MyTrigger', { handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('foo'), }); @@ -33,7 +34,7 @@ test('before/after', () => { // WHEN const myTrigger = new triggers.TriggerFunction(stack, 'MyTrigger', { - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('zoo'), handler: 'index.handler', @@ -73,13 +74,13 @@ test('multiple functions', () => { // WHEN new triggers.TriggerFunction(stack, 'MyTrigger', { handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('foo'), }); new triggers.TriggerFunction(stack, 'MySecondTrigger', { handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('bar'), }); @@ -95,7 +96,7 @@ test('minimal trigger', () => { const stack = new Stack(); const func = new lambda.Function(stack, 'MyFunction', { handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('foo'), }); @@ -118,7 +119,7 @@ test('trigger with optional properties', () => { const stack = new Stack(); const func = new lambda.Function(stack, 'MyFunction', { handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_16_X, + runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('foo'), }); From 1edca7e9fee00fa5cf65f885a0d81d32c1ee59bc Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Tue, 5 Sep 2023 15:16:22 +0200 Subject: [PATCH 2/6] Remove new constant --- .../test/http/lambda.test.ts | 12 +- .../test/websocket/iam.test.ts | 4 +- .../test/websocket/lambda.test.ts | 4 +- .../test/http/lambda.test.ts | 6 +- .../test/websocket/lambda.test.ts | 4 +- .../lambda/lambda-function-action.test.ts | 6 +- .../test/s3-bucket.test.ts | 4 +- .../test/function.test.ts | 4 +- .../test/s3objectlambda.test.ts | 4 +- .../test/authorizers/lambda.test.ts | 21 +-- .../aws-apigateway/test/cors.test.ts | 3 +- .../aws-apigateway/test/deployment.test.ts | 5 +- .../test/integrations/lambda.test.ts | 15 +- .../aws-apigateway/test/lambda-api.test.ts | 15 +- .../aws-apigateway/test/method.test.ts | 3 +- .../aws-appsync/test/appsync-auth.test.ts | 5 +- .../test/appsync-caching-config.test.ts | 3 +- .../aws-appsync/test/appsync-lambda.test.ts | 7 +- .../test/appsync-mapping-template.test.ts | 3 +- .../test/hooks.test.ts | 7 +- .../aws-cloudfront/test/distribution.test.ts | 11 +- .../test/experimental/edge-function.test.ts | 7 +- .../test/web-distribution.test.ts | 9 +- .../aws-cloudtrail/test/cloudtrail.test.ts | 6 +- .../lambda/custom-deployment-config.test.ts | 3 +- .../test/lambda/deployment-group.test.ts | 3 +- .../test/lambda/lambda-invoke-action.test.ts | 3 +- .../test/pipeline.test.ts | 3 +- .../aws-cognito/test/user-pool.test.ts | 7 +- .../test/api-gateway/api-gateway.test.ts | 3 +- .../test/destinations.test.ts | 3 +- .../test/test-function.ts | 3 +- .../lib/helpers-internal/defaults.ts | 13 -- .../aws-lambda/lib/helpers-internal/index.ts | 1 - .../aws-cdk-lib/aws-lambda/test/adot.test.ts | 3 +- .../aws-cdk-lib/aws-lambda/test/alias.test.ts | 43 +++-- .../aws-lambda/test/architecture.test.ts | 3 +- .../aws-cdk-lib/aws-lambda/test/code.test.ts | 23 ++- .../test/event-source-mapping.test.ts | 3 +- .../aws-lambda/test/function-hash.test.ts | 87 ++++----- .../aws-lambda/test/function-url.test.ts | 13 +- .../aws-lambda/test/function.test.ts | 177 +++++++++--------- .../aws-lambda/test/lambda-insights.test.ts | 2 +- .../aws-lambda/test/lambda-version.test.ts | 15 +- .../aws-lambda/test/layers.test.ts | 7 +- .../aws-lambda/test/singleton-lambda.test.ts | 5 +- .../aws-lambda/test/vpc-lambda.test.ts | 21 +-- .../aws-logs-destinations/test/lambda.test.ts | 107 ----------- .../aws-cdk-lib/aws-rds/test/instance.test.ts | 3 +- .../aws-s3-deployment/test/content.test.ts | 5 +- .../test/lambda/lambda.test.ts | 13 +- .../test/rotation-schedule.test.ts | 13 +- .../aws-secretsmanager/test/secret.test.ts | 3 +- .../aws-ses-actions/test/actions.test.ts | 2 +- .../aws-sns-subscriptions/test/subs.test.ts | 25 ++- .../test/lambda/invoke.test.ts | 3 +- .../test/provider-framework/provider.test.ts | 27 ++- .../waiter-state-machine.test.ts | 7 +- packages/aws-cdk-lib/package.json | 1 - .../triggers/test/triggers.test.ts | 13 +- 60 files changed, 337 insertions(+), 497 deletions(-) delete mode 100644 packages/aws-cdk-lib/aws-lambda/lib/helpers-internal/defaults.ts delete mode 100644 packages/aws-cdk-lib/aws-lambda/lib/helpers-internal/index.ts diff --git a/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/http/lambda.test.ts b/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/http/lambda.test.ts index 2a59960f9c33a..b80f48c12b680 100644 --- a/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/http/lambda.test.ts +++ b/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/http/lambda.test.ts @@ -1,7 +1,7 @@ import { Match, Template } from 'aws-cdk-lib/assertions'; import { HttpApi } from '@aws-cdk/aws-apigatewayv2-alpha'; import { Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda'; -import { DEFAULT_UNITTEST_RUNTIME } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; +import { lambda.Runtime.NODEJS_LATEST } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; import { Duration, Stack } from 'aws-cdk-lib'; import { DummyRouteIntegration } from './integration'; import { HttpLambdaAuthorizer, HttpLambdaResponseType } from '../../lib'; @@ -14,7 +14,7 @@ describe('HttpLambdaAuthorizer', () => { const api = new HttpApi(stack, 'HttpApi'); const handler = new Function(stack, 'auth-function', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: Code.fromInline('exports.handler = () => {return true}'), handler: 'index.handler', }); @@ -50,7 +50,7 @@ describe('HttpLambdaAuthorizer', () => { const api = new HttpApi(stack, 'HttpApi'); const handler = new Function(stack, 'auth-function', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: Code.fromInline('exports.handler = () => {return true}'), handler: 'index.handler', }); @@ -79,7 +79,7 @@ describe('HttpLambdaAuthorizer', () => { const api = new HttpApi(stack, 'HttpApi'); const handler = new Function(stack, 'auth-function', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: Code.fromInline('exports.handler = () => {return true}'), handler: 'index.handler', }); @@ -108,7 +108,7 @@ describe('HttpLambdaAuthorizer', () => { const api = new HttpApi(stack, 'HttpApi'); const handler = new Function(stack, 'auth-function', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: Code.fromInline('exports.handler = () => {return true}'), handler: 'index.handler', }); @@ -137,7 +137,7 @@ describe('HttpLambdaAuthorizer', () => { const api = new HttpApi(stack, 'HttpApi'); const handler = new Function(stack, 'auth-functon', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: Code.fromInline('exports.handler = () => {return true}'), handler: 'index.handler', }); diff --git a/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/websocket/iam.test.ts b/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/websocket/iam.test.ts index 9bf067ec2b9ce..b30a830ff5480 100644 --- a/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/websocket/iam.test.ts +++ b/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/websocket/iam.test.ts @@ -2,7 +2,7 @@ import { Template } from 'aws-cdk-lib/assertions'; import { WebSocketApi } from '@aws-cdk/aws-apigatewayv2-alpha'; import { WebSocketLambdaIntegration } from '@aws-cdk/aws-apigatewayv2-integrations-alpha'; import { Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda'; -import { DEFAULT_UNITTEST_RUNTIME } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; +import { lambda.Runtime.NODEJS_LATEST } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; import { Stack } from 'aws-cdk-lib'; import { WebSocketIamAuthorizer } from '../../lib'; @@ -11,7 +11,7 @@ describe('WebSocketLambdaAuthorizer', () => { const stack = new Stack(); const handler = new Function(stack, 'auth-function', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: Code.fromInline('exports.handler = () => {return true}'), handler: 'index.handler', }); diff --git a/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/websocket/lambda.test.ts b/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/websocket/lambda.test.ts index e1a711d1ac097..df5178ddaff4c 100644 --- a/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/websocket/lambda.test.ts +++ b/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/websocket/lambda.test.ts @@ -2,7 +2,7 @@ import { Template } from 'aws-cdk-lib/assertions'; import { WebSocketApi } from '@aws-cdk/aws-apigatewayv2-alpha'; import { WebSocketLambdaIntegration } from '@aws-cdk/aws-apigatewayv2-integrations-alpha'; import { Code, Function } from 'aws-cdk-lib/aws-lambda'; -import { DEFAULT_UNITTEST_RUNTIME } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; +import { lambda.Runtime.NODEJS_LATEST } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; import { Stack } from 'aws-cdk-lib'; import { WebSocketLambdaAuthorizer } from '../../lib'; @@ -12,7 +12,7 @@ describe('WebSocketLambdaAuthorizer', () => { const stack = new Stack(); const handler = new Function(stack, 'auth-function', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: Code.fromInline('exports.handler = () => {return true}'), handler: 'index.handler', }); diff --git a/packages/@aws-cdk/aws-apigatewayv2-integrations-alpha/test/http/lambda.test.ts b/packages/@aws-cdk/aws-apigatewayv2-integrations-alpha/test/http/lambda.test.ts index d53d6e6345d67..f615746ada9be 100644 --- a/packages/@aws-cdk/aws-apigatewayv2-integrations-alpha/test/http/lambda.test.ts +++ b/packages/@aws-cdk/aws-apigatewayv2-integrations-alpha/test/http/lambda.test.ts @@ -1,7 +1,7 @@ import { Match, Template } from 'aws-cdk-lib/assertions'; import { HttpApi, HttpRoute, HttpRouteKey, MappingValue, ParameterMapping, PayloadFormatVersion } from '@aws-cdk/aws-apigatewayv2-alpha'; import { Code, Function } from 'aws-cdk-lib/aws-lambda'; -import { DEFAULT_UNITTEST_RUNTIME } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; +import { lambda.Runtime.NODEJS_LATEST } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; import { App, Stack } from 'aws-cdk-lib'; import { HttpLambdaIntegration } from '../../lib'; @@ -112,7 +112,7 @@ describe('LambdaProxyIntegration', () => { function fooFunction(stack: Stack, id: string) { return new Function(stack, id, { code: Code.fromInline('foo'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', }); -} \ No newline at end of file +} diff --git a/packages/@aws-cdk/aws-apigatewayv2-integrations-alpha/test/websocket/lambda.test.ts b/packages/@aws-cdk/aws-apigatewayv2-integrations-alpha/test/websocket/lambda.test.ts index 530a6bc50e942..9ad9f16222891 100644 --- a/packages/@aws-cdk/aws-apigatewayv2-integrations-alpha/test/websocket/lambda.test.ts +++ b/packages/@aws-cdk/aws-apigatewayv2-integrations-alpha/test/websocket/lambda.test.ts @@ -1,7 +1,7 @@ import { Template } from 'aws-cdk-lib/assertions'; import { WebSocketApi } from '@aws-cdk/aws-apigatewayv2-alpha'; import { Code, Function } from 'aws-cdk-lib/aws-lambda'; -import { DEFAULT_UNITTEST_RUNTIME } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; +import { lambda.Runtime.NODEJS_LATEST } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; import { Stack } from 'aws-cdk-lib'; import { WebSocketLambdaIntegration } from '../../lib'; @@ -51,7 +51,7 @@ describe('LambdaWebSocketIntegration', () => { function fooFunction(stack: Stack, id: string) { return new Function(stack, id, { code: Code.fromInline('foo'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', }); } diff --git a/packages/@aws-cdk/aws-iot-actions-alpha/test/lambda/lambda-function-action.test.ts b/packages/@aws-cdk/aws-iot-actions-alpha/test/lambda/lambda-function-action.test.ts index e78e2492529eb..8c8d1555af806 100644 --- a/packages/@aws-cdk/aws-iot-actions-alpha/test/lambda/lambda-function-action.test.ts +++ b/packages/@aws-cdk/aws-iot-actions-alpha/test/lambda/lambda-function-action.test.ts @@ -3,7 +3,7 @@ import * as iot from '@aws-cdk/aws-iot-alpha'; import * as lambda from 'aws-cdk-lib/aws-lambda'; import * as cdk from 'aws-cdk-lib'; import * as actions from '../../lib'; -import { DEFAULT_UNITTEST_RUNTIME } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; +import { lambda.Runtime.NODEJS_LATEST } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; test('create a topic rule with lambda action and a lambda permission to be invoked by the topic rule', () => { // GIVEN @@ -12,7 +12,7 @@ test('create a topic rule with lambda action and a lambda permission to be invok sql: iot.IotSql.fromStringAsVer20160323("SELECT topic(2) as device_id FROM 'device/+/data'"), }); const func = new lambda.Function(stack, 'MyFunction', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', code: lambda.Code.fromInline('console.log("foo")'), }); @@ -61,7 +61,7 @@ test('create two different permissions, when two topic rules have the same actio // GIVEN const stack = new cdk.Stack(); const func = new lambda.Function(stack, 'MyFunction', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', code: lambda.Code.fromInline('console.log("foo")'), }); diff --git a/packages/@aws-cdk/aws-kinesisfirehose-destinations-alpha/test/s3-bucket.test.ts b/packages/@aws-cdk/aws-kinesisfirehose-destinations-alpha/test/s3-bucket.test.ts index 6dde373dbf332..a2f9be9829be1 100644 --- a/packages/@aws-cdk/aws-kinesisfirehose-destinations-alpha/test/s3-bucket.test.ts +++ b/packages/@aws-cdk/aws-kinesisfirehose-destinations-alpha/test/s3-bucket.test.ts @@ -3,7 +3,7 @@ import * as iam from 'aws-cdk-lib/aws-iam'; import * as firehose from '@aws-cdk/aws-kinesisfirehose-alpha'; import * as kms from 'aws-cdk-lib/aws-kms'; import * as lambda from 'aws-cdk-lib/aws-lambda'; -import { DEFAULT_UNITTEST_RUNTIME } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; +import { lambda.Runtime.NODEJS_LATEST } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; import * as logs from 'aws-cdk-lib/aws-logs'; import * as s3 from 'aws-cdk-lib/aws-s3'; import * as cdk from 'aws-cdk-lib'; @@ -241,7 +241,7 @@ describe('S3 destination', () => { beforeEach(() => { lambdaFunction = new lambda.Function(stack, 'DataProcessorFunction', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromInline('foo'), handler: 'bar', }); diff --git a/packages/@aws-cdk/aws-lambda-python-alpha/test/function.test.ts b/packages/@aws-cdk/aws-lambda-python-alpha/test/function.test.ts index 2d60c6210428b..70dd4ab23b178 100644 --- a/packages/@aws-cdk/aws-lambda-python-alpha/test/function.test.ts +++ b/packages/@aws-cdk/aws-lambda-python-alpha/test/function.test.ts @@ -1,7 +1,7 @@ import * as path from 'path'; import { Template } from 'aws-cdk-lib/assertions'; import { Code, Runtime } from 'aws-cdk-lib/aws-lambda'; -import { DEFAULT_UNITTEST_RUNTIME } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; +import { lambda.Runtime.NODEJS_LATEST } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; import { AssetHashType, DockerImage, Stack } from 'aws-cdk-lib'; import { PythonFunction } from '../lib'; import { Bundling, BundlingProps } from '../lib/bundling'; @@ -113,7 +113,7 @@ test('throws when entry does not exist', () => { test('throws with the wrong runtime family', () => { expect(() => new PythonFunction(stack, 'handler1', { entry: path.join(__dirname, 'lambda-handler'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, })).toThrow(/Only `PYTHON` runtimes are supported/); }); diff --git a/packages/@aws-cdk/aws-s3objectlambda-alpha/test/s3objectlambda.test.ts b/packages/@aws-cdk/aws-s3objectlambda-alpha/test/s3objectlambda.test.ts index 024f74b2c00ed..5ec3514e080c1 100644 --- a/packages/@aws-cdk/aws-s3objectlambda-alpha/test/s3objectlambda.test.ts +++ b/packages/@aws-cdk/aws-s3objectlambda-alpha/test/s3objectlambda.test.ts @@ -1,6 +1,6 @@ import { Template } from 'aws-cdk-lib/assertions'; import * as lambda from 'aws-cdk-lib/aws-lambda'; -import { DEFAULT_UNITTEST_RUNTIME } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; +import { lambda.Runtime.NODEJS_LATEST } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; import * as s3 from 'aws-cdk-lib/aws-s3'; import * as cdk from 'aws-cdk-lib'; import { AccessPoint } from '../lib'; @@ -13,7 +13,7 @@ beforeEach(() => { stack = new cdk.Stack(); bucket = new s3.Bucket(stack, 'MyBucket'); handler = new lambda.Function(stack, 'MyFunction', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.hello', code: new lambda.InlineCode('def hello(): pass'), }); diff --git a/packages/aws-cdk-lib/aws-apigateway/test/authorizers/lambda.test.ts b/packages/aws-cdk-lib/aws-apigateway/test/authorizers/lambda.test.ts index b100d65f39b03..0dcfbd2c269d7 100644 --- a/packages/aws-cdk-lib/aws-apigateway/test/authorizers/lambda.test.ts +++ b/packages/aws-cdk-lib/aws-apigateway/test/authorizers/lambda.test.ts @@ -1,7 +1,6 @@ import { Match, Template } from '../../../assertions'; import * as iam from '../../../aws-iam'; import * as lambda from '../../../aws-lambda'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../../aws-lambda/lib/helpers-internal'; import { Duration, Stack } from '../../../core'; import { AuthorizationType, IdentitySource, RequestAuthorizer, RestApi, TokenAuthorizer } from '../../lib'; @@ -12,7 +11,7 @@ describe('lambda authorizer', () => { const func = new lambda.Function(stack, 'myfunction', { handler: 'handler', code: lambda.Code.fromInline('foo'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const auth = new TokenAuthorizer(stack, 'myauthorizer', { @@ -85,7 +84,7 @@ describe('lambda authorizer', () => { const func = new lambda.Function(stack, 'myfunction', { handler: 'handler', code: lambda.Code.fromInline('foo'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const auth = new RequestAuthorizer(stack, 'myauthorizer', { @@ -160,7 +159,7 @@ describe('lambda authorizer', () => { const func = new lambda.Function(stack, 'myfunction', { handler: 'handler', code: lambda.Code.fromInline('foo'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); expect(() => new RequestAuthorizer(stack, 'myauthorizer', { @@ -176,7 +175,7 @@ describe('lambda authorizer', () => { const func = new lambda.Function(stack, 'myfunction', { handler: 'handler', code: lambda.Code.fromInline('foo'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const auth = new TokenAuthorizer(stack, 'myauthorizer', { @@ -249,7 +248,7 @@ describe('lambda authorizer', () => { const func = new lambda.Function(stack, 'myfunction', { handler: 'handler', code: lambda.Code.fromInline('foo'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const auth = new RequestAuthorizer(stack, 'myauthorizer', { @@ -320,7 +319,7 @@ describe('lambda authorizer', () => { const func = new lambda.Function(stack, 'myfunction', { handler: 'handler', code: lambda.Code.fromInline('foo'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const role = new iam.Role(stack, 'authorizerassumerole', { @@ -410,7 +409,7 @@ describe('lambda authorizer', () => { const func = new lambda.Function(stack, 'myfunction', { handler: 'handler', code: lambda.Code.fromInline('foo'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const role = new iam.Role(stack, 'authorizerassumerole', { @@ -501,7 +500,7 @@ describe('lambda authorizer', () => { const func = new lambda.Function(stack, 'myfunction', { handler: 'handler', code: lambda.Code.fromInline('foo'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const auth = new TokenAuthorizer(stack, 'myauthorizer', { handler: func, @@ -515,7 +514,7 @@ describe('lambda authorizer', () => { const func = new lambda.Function(stack, 'myfunction', { handler: 'handler', code: lambda.Code.fromInline('foo'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const auth = new RequestAuthorizer(stack, 'myauthorizer', { handler: func, @@ -560,7 +559,7 @@ describe('lambda authorizer', () => { const func = new lambda.Function(stack, 'myfunction', { handler: 'handler', code: lambda.Code.fromInline('foo'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const auth = new RequestAuthorizer(stack, 'myauthorizer', { diff --git a/packages/aws-cdk-lib/aws-apigateway/test/cors.test.ts b/packages/aws-cdk-lib/aws-apigateway/test/cors.test.ts index 17f5589dda4ce..d369fb60c6021 100644 --- a/packages/aws-cdk-lib/aws-apigateway/test/cors.test.ts +++ b/packages/aws-cdk-lib/aws-apigateway/test/cors.test.ts @@ -1,6 +1,5 @@ import { Template } from '../../assertions'; import * as lambda from '../../aws-lambda'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; import { Duration, Stack } from '../../core'; import * as apigw from '../lib'; @@ -635,7 +634,7 @@ describe('cors', () => { const handler = new lambda.Function(stack, 'handler', { handler: 'index.handler', code: lambda.Code.fromInline('boom'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); // WHEN diff --git a/packages/aws-cdk-lib/aws-apigateway/test/deployment.test.ts b/packages/aws-cdk-lib/aws-apigateway/test/deployment.test.ts index fe2795756e4d8..667634408b1b2 100644 --- a/packages/aws-cdk-lib/aws-apigateway/test/deployment.test.ts +++ b/packages/aws-cdk-lib/aws-apigateway/test/deployment.test.ts @@ -1,7 +1,6 @@ import * as path from 'path'; import { Template } from '../../assertions'; import * as lambda from '../../aws-lambda'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; import { CfnResource, Lazy, Stack } from '../../core'; import * as apigateway from '../lib'; @@ -199,12 +198,12 @@ describe('deployment', () => { const stack2 = new Stack(); const handler1 = new lambda.Function(stack1, 'handler1', { code: lambda.Code.fromAsset(path.join(__dirname, 'lambda')), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', }); const handler2 = new lambda.Function(stack2, 'handler2', { code: lambda.Code.fromAsset(path.join(__dirname, 'lambda')), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', }); diff --git a/packages/aws-cdk-lib/aws-apigateway/test/integrations/lambda.test.ts b/packages/aws-cdk-lib/aws-apigateway/test/integrations/lambda.test.ts index fe2ed328c085c..d1c182d356d63 100644 --- a/packages/aws-cdk-lib/aws-apigateway/test/integrations/lambda.test.ts +++ b/packages/aws-cdk-lib/aws-apigateway/test/integrations/lambda.test.ts @@ -1,6 +1,5 @@ import { Match, Template } from '../../../assertions'; import * as lambda from '../../../aws-lambda'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../../aws-lambda/lib/helpers-internal'; import * as cdk from '../../../core'; import * as apigateway from '../../lib'; @@ -55,7 +54,7 @@ describe('lambda', () => { // GIVEN const stack = new cdk.Stack(); const fn = new lambda.Function(stack, 'Handler', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromInline('foo'), handler: 'index.handler', }); @@ -103,7 +102,7 @@ describe('lambda', () => { // GIVEN const stack = new cdk.Stack(); const fn = new lambda.Function(stack, 'Handler', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromInline('foo'), handler: 'index.handler', }); @@ -139,7 +138,7 @@ describe('lambda', () => { // GIVEN const stack = new cdk.Stack(); const fn = new lambda.Function(stack, 'Handler', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromInline('foo'), handler: 'index.handler', }); @@ -163,7 +162,7 @@ describe('lambda', () => { const api = new apigateway.RestApi(stack, 'test-api'); const handler = new lambda.Function(stack, 'MyFunc', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', code: lambda.Code.fromInline('loo'), }); @@ -229,7 +228,7 @@ describe('lambda', () => { }); const handler = new lambda.Function(stack, 'MyFunc', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', code: lambda.Code.fromInline('loo'), }); @@ -250,7 +249,7 @@ describe('lambda', () => { const method = restapi.root.addMethod('ANY'); const handler = new lambda.Function(stack, 'MyFunc', { functionName: 'ThisFunction', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', code: lambda.Code.fromInline('loo'), }); @@ -270,7 +269,7 @@ describe('lambda', () => { const restapi = new apigateway.RestApi(stack, 'RestApi'); const method = restapi.root.addMethod('ANY'); const handler = new lambda.Function(stack, 'MyFunc', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', code: lambda.Code.fromInline('loo'), }); diff --git a/packages/aws-cdk-lib/aws-apigateway/test/lambda-api.test.ts b/packages/aws-cdk-lib/aws-apigateway/test/lambda-api.test.ts index 5092af31d60f4..57150bbc3f230 100644 --- a/packages/aws-cdk-lib/aws-apigateway/test/lambda-api.test.ts +++ b/packages/aws-cdk-lib/aws-apigateway/test/lambda-api.test.ts @@ -1,6 +1,5 @@ import { Match, Template } from '../../assertions'; import * as lambda from '../../aws-lambda'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; import * as cdk from '../../core'; import * as apigw from '../lib'; import { LambdaRestApi } from '../lib'; @@ -13,7 +12,7 @@ describe('lambda api', () => { const handler = new lambda.Function(stack, 'handler', { handler: 'index.handler', code: lambda.Code.fromInline('boom'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); // WHEN @@ -75,7 +74,7 @@ describe('lambda api', () => { const handler = new lambda.Function(stack, 'handler', { handler: 'index.handler', code: lambda.Code.fromInline('boom'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const alias = new lambda.Alias(stack, 'alias', { aliasName: 'my-alias', @@ -140,7 +139,7 @@ describe('lambda api', () => { const handler = new lambda.Function(stack, 'handler', { handler: 'index.handler', code: lambda.Code.fromInline('boom'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); // WHEN @@ -204,7 +203,7 @@ describe('lambda api', () => { const handler = new lambda.Function(stack, 'handler', { handler: 'index.handler', code: lambda.Code.fromInline('boom'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); expect(() => new apigw.LambdaRestApi(stack, 'lambda-rest-api', { @@ -225,7 +224,7 @@ describe('lambda api', () => { const handler = new lambda.Function(stack, 'handler', { handler: 'index.handler', code: lambda.Code.fromInline('boom'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); // WHEN @@ -279,7 +278,7 @@ describe('lambda api', () => { const handler = new lambda.Function(stack, 'handler', { handler: 'index.handler', code: lambda.Code.fromInline('boom'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); // WHEN @@ -341,7 +340,7 @@ describe('lambda api', () => { handler: new lambda.Function(stack, 'handler', { handler: 'index.handler', code: lambda.Code.fromInline('boom'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }), restApiName: cdk.PhysicalName.GENERATE_IF_NEEDED, }); diff --git a/packages/aws-cdk-lib/aws-apigateway/test/method.test.ts b/packages/aws-cdk-lib/aws-apigateway/test/method.test.ts index bbf4c1bbd8a24..f69fdac969d74 100644 --- a/packages/aws-cdk-lib/aws-apigateway/test/method.test.ts +++ b/packages/aws-cdk-lib/aws-apigateway/test/method.test.ts @@ -4,7 +4,6 @@ import * as iam from '../../aws-iam'; import * as lambda from '../../aws-lambda'; import * as cdk from '../../core'; import * as apigw from '../lib'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; const DUMMY_AUTHORIZER: apigw.IAuthorizer = { authorizerId: 'dummyauthorizer', @@ -644,7 +643,7 @@ describe('method', () => { const func = new lambda.Function(stack, 'myfunction', { handler: 'handler', code: lambda.Code.fromInline('foo'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const auth = new apigw.TokenAuthorizer(stack, 'myauthorizer1', { diff --git a/packages/aws-cdk-lib/aws-appsync/test/appsync-auth.test.ts b/packages/aws-cdk-lib/aws-appsync/test/appsync-auth.test.ts index 5ae168d19c323..170dae5d34229 100644 --- a/packages/aws-cdk-lib/aws-appsync/test/appsync-auth.test.ts +++ b/packages/aws-cdk-lib/aws-appsync/test/appsync-auth.test.ts @@ -4,7 +4,6 @@ import * as cognito from '../../aws-cognito'; import * as lambda from '../../aws-lambda'; import * as cdk from '../../core'; import * as appsync from '../lib'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; // GIVEN let stack: cdk.Stack; @@ -638,7 +637,7 @@ describe('AppSync Lambda Authorization', () => { let fn: lambda.Function; beforeEach(() => { fn = new lambda.Function(stack, 'auth-function', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', code: lambda.Code.fromInline('/* lambda authentication code here.*/'), }); @@ -926,4 +925,4 @@ describe('AppSync Lambda Authorization', () => { }, })).toThrow('Missing Lambda Configuration'); }); -}); \ No newline at end of file +}); diff --git a/packages/aws-cdk-lib/aws-appsync/test/appsync-caching-config.test.ts b/packages/aws-cdk-lib/aws-appsync/test/appsync-caching-config.test.ts index 6a50665d2ec8b..b1475e412f3ff 100644 --- a/packages/aws-cdk-lib/aws-appsync/test/appsync-caching-config.test.ts +++ b/packages/aws-cdk-lib/aws-appsync/test/appsync-caching-config.test.ts @@ -4,7 +4,6 @@ import * as lambda from '../../aws-lambda'; import * as cdk from '../../core'; import { Duration } from '../../core'; import * as appsync from '../lib'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; let stack: cdk.Stack; let api: appsync.GraphqlApi; @@ -26,7 +25,7 @@ describe('Lambda caching config', () => { func = new lambda.Function(stack, 'func', { code: lambda.Code.fromAsset(path.join(__dirname, 'verify/lambda-tutorial')), handler: 'lambda-tutorial.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); }); diff --git a/packages/aws-cdk-lib/aws-appsync/test/appsync-lambda.test.ts b/packages/aws-cdk-lib/aws-appsync/test/appsync-lambda.test.ts index b497d143dd386..29ba4d27f6446 100644 --- a/packages/aws-cdk-lib/aws-appsync/test/appsync-lambda.test.ts +++ b/packages/aws-cdk-lib/aws-appsync/test/appsync-lambda.test.ts @@ -3,7 +3,6 @@ import { Template } from '../../assertions'; import * as lambda from '../../aws-lambda'; import * as cdk from '../../core'; import * as appsync from '../lib'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; // GLOBAL GIVEN let stack: cdk.Stack; @@ -23,7 +22,7 @@ describe('Lambda Data Source configuration', () => { func = new lambda.Function(stack, 'func', { code: lambda.Code.fromAsset(path.join(__dirname, 'verify/iam-query')), handler: 'iam-query.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); }); @@ -79,7 +78,7 @@ describe('Lambda Data Source configuration', () => { const dummyFunction = new lambda.Function(newStack, 'func', { code: lambda.Code.fromAsset(path.join(__dirname, 'verify/iam-query')), handler: 'iam-query.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); graphqlapi.addLambdaDataSource(`data-${badCharacter}-source`, dummyFunction); @@ -133,7 +132,7 @@ describe('adding lambda data source from imported api', () => { func = new lambda.Function(stack, 'func', { code: lambda.Code.fromAsset(path.join(__dirname, 'verify/iam-query')), handler: 'iam-query.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); }); diff --git a/packages/aws-cdk-lib/aws-appsync/test/appsync-mapping-template.test.ts b/packages/aws-cdk-lib/aws-appsync/test/appsync-mapping-template.test.ts index aceacc39d8eef..fd9ab94b91341 100644 --- a/packages/aws-cdk-lib/aws-appsync/test/appsync-mapping-template.test.ts +++ b/packages/aws-cdk-lib/aws-appsync/test/appsync-mapping-template.test.ts @@ -3,7 +3,6 @@ import { Template } from '../../assertions'; import * as lambda from '../../aws-lambda'; import * as cdk from '../../core'; import * as appsync from '../lib'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; let stack: cdk.Stack; let api: appsync.GraphqlApi; @@ -27,7 +26,7 @@ describe('Lambda Mapping Templates', () => { func = new lambda.Function(stack, 'func', { code: lambda.Code.fromAsset(path.join(__dirname, 'verify/lambda-tutorial')), handler: 'lambda-tutorial.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); }); diff --git a/packages/aws-cdk-lib/aws-autoscaling-hooktargets/test/hooks.test.ts b/packages/aws-cdk-lib/aws-autoscaling-hooktargets/test/hooks.test.ts index a32359bb5bac9..60e59fd9337bf 100644 --- a/packages/aws-cdk-lib/aws-autoscaling-hooktargets/test/hooks.test.ts +++ b/packages/aws-cdk-lib/aws-autoscaling-hooktargets/test/hooks.test.ts @@ -4,7 +4,6 @@ import * as ec2 from '../../aws-ec2'; import * as iam from '../../aws-iam'; import * as kms from '../../aws-kms'; import * as lambda from '../../aws-lambda'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; import * as sns from '../../aws-sns'; import * as sqs from '../../aws-sqs'; import { Stack } from '../../core'; @@ -121,7 +120,7 @@ describe('given an AutoScalingGroup and no role', () => { // GIVEN const fn = new lambda.Function(stack, 'Fn', { code: lambda.Code.fromInline('foo'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.index', }); @@ -165,7 +164,7 @@ describe('given an AutoScalingGroup and no role', () => { const key = new kms.Key(stack, 'key'); const fn = new lambda.Function(stack, 'Fn', { code: lambda.Code.fromInline('foo'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.index', }); @@ -297,7 +296,7 @@ describe('given an AutoScalingGroup and a role', () => { // GIVEN const fn = new lambda.Function(stack, 'Fn', { code: lambda.Code.fromInline('foo'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.index', }); const myrole = new iam.Role(stack, 'MyRole', { diff --git a/packages/aws-cdk-lib/aws-cloudfront/test/distribution.test.ts b/packages/aws-cdk-lib/aws-cloudfront/test/distribution.test.ts index 559dbd6008e0f..bedd391865792 100644 --- a/packages/aws-cdk-lib/aws-cloudfront/test/distribution.test.ts +++ b/packages/aws-cdk-lib/aws-cloudfront/test/distribution.test.ts @@ -22,7 +22,6 @@ import { SecurityPolicyProtocol, SSLMethod, } from '../lib'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; let app: App; let stack: Stack; @@ -667,7 +666,7 @@ describe('with Lambda@Edge functions', () => { beforeEach(() => { lambdaFunction = new lambda.Function(stack, 'Function', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromInline('whatever'), handler: 'index.handler', }); @@ -795,7 +794,7 @@ describe('with Lambda@Edge functions', () => { test('with removable env vars', () => { const envLambdaFunction = new lambda.Function(stack, 'EnvFunction', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromInline('whateverwithenv'), handler: 'index.handler', }); @@ -823,7 +822,7 @@ describe('with Lambda@Edge functions', () => { test('with incompatible env vars', () => { const envLambdaFunction = new lambda.Function(stack, 'EnvFunction', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromInline('whateverwithenv'), handler: 'index.handler', environment: { @@ -849,7 +848,7 @@ describe('with Lambda@Edge functions', () => { test('with singleton function', () => { const singleton = new lambda.SingletonFunction(stack, 'Singleton', { uuid: 'singleton-for-cloudfront', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromInline('code'), handler: 'index.handler', }); @@ -1241,4 +1240,4 @@ test('render distribution behavior with realtime log config - multiple behaviors }], }, })); -}); \ No newline at end of file +}); diff --git a/packages/aws-cdk-lib/aws-cloudfront/test/experimental/edge-function.test.ts b/packages/aws-cdk-lib/aws-cloudfront/test/experimental/edge-function.test.ts index aebaa68d1edf5..5b927a76ba2bb 100644 --- a/packages/aws-cdk-lib/aws-cloudfront/test/experimental/edge-function.test.ts +++ b/packages/aws-cdk-lib/aws-cloudfront/test/experimental/edge-function.test.ts @@ -5,7 +5,6 @@ import * as iam from '../../../aws-iam'; import * as lambda from '../../../aws-lambda'; import * as cdk from '../../../core'; import * as cloudfront from '../../lib'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../../aws-lambda/lib/helpers-internal'; let app: cdk.App; let stack: cdk.Stack; @@ -91,7 +90,7 @@ describe('stacks', () => { Code: { ZipFile: 'foo' }, Handler: 'index.handler', Role: { 'Fn::GetAtt': ['MyFnServiceRoleF3016589', 'Arn'] }, - Runtime: 'nodejs99.x', + Runtime: lambda.Runtime.NODEJS_LATEST.name, }); Template.fromStack(fnStack).hasResourceProperties('AWS::Lambda::Version', { FunctionName: { Ref: 'MyFn6F8F742F' }, @@ -153,7 +152,7 @@ describe('stacks', () => { Code: { ZipFile: 'foo' }, Handler: 'index.handler', Role: { 'Fn::GetAtt': ['MyFnServiceRole3F9D41E1', 'Arn'] }, - Runtime: 'nodejs99.x', + Runtime: lambda.Runtime.NODEJS_LATEST.name, }); Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Version', { FunctionName: { Ref: 'MyFn223608AD' }, @@ -311,7 +310,7 @@ function defaultEdgeFunctionProps(stackId?: string) { return { code: lambda.Code.fromInline('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, stackId: stackId, }; } diff --git a/packages/aws-cdk-lib/aws-cloudfront/test/web-distribution.test.ts b/packages/aws-cdk-lib/aws-cloudfront/test/web-distribution.test.ts index 12d0b9faf9f6b..7202b28052e84 100644 --- a/packages/aws-cdk-lib/aws-cloudfront/test/web-distribution.test.ts +++ b/packages/aws-cdk-lib/aws-cloudfront/test/web-distribution.test.ts @@ -21,7 +21,6 @@ import { ViewerCertificate, ViewerProtocolPolicy, } from '../lib'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; /* eslint-disable quote-props */ @@ -838,7 +837,7 @@ added the ellipsis so a user would know there was more to r...`, const lambdaFunction = new lambda.Function(stack, 'Lambda', { code: lambda.Code.fromInline('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); new CloudFrontWebDistribution(stack, 'AnAmazingWebsiteProbably', { @@ -887,7 +886,7 @@ added the ellipsis so a user would know there was more to r...`, const lambdaFunction = new lambda.Function(stack, 'Lambda', { code: lambda.Code.fromInline('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); lambdaFunction.addEnvironment('KEY', 'value', { removeInEdge: true }); @@ -924,7 +923,7 @@ added the ellipsis so a user would know there was more to r...`, const lambdaFunction = new lambda.Function(stack, 'Lambda', { code: lambda.Code.fromInline('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, environment: { KEY: 'value', }, @@ -1308,7 +1307,7 @@ added the ellipsis so a user would know there was more to r...`, const fn = new lambda.Function(stack, 'Lambda', { code: lambda.Code.fromInline('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const lambdaVersion = new lambda.Version(stack, 'LambdaVersion', { lambda: fn }); diff --git a/packages/aws-cdk-lib/aws-cloudtrail/test/cloudtrail.test.ts b/packages/aws-cdk-lib/aws-cloudtrail/test/cloudtrail.test.ts index 798b791150604..785806fdc80db 100644 --- a/packages/aws-cdk-lib/aws-cloudtrail/test/cloudtrail.test.ts +++ b/packages/aws-cdk-lib/aws-cloudtrail/test/cloudtrail.test.ts @@ -8,7 +8,7 @@ import * as s3 from '../../aws-s3'; import * as sns from '../../aws-sns'; import { Stack } from '../../core'; import { ManagementEventSources, ReadWriteType, Trail, InsightType } from '../lib'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; +import { lambda.Runtime.NODEJS_LATEST } from '../../aws-lambda/lib/helpers-internal'; const ExpectedBucketPolicyProperties = { PolicyDocument: { @@ -572,7 +572,7 @@ describe('cloudtrail', () => { test('for Lambda function data event', () => { const stack = getTestStack(); const lambdaFunction = new lambda.Function(stack, 'LambdaFunction', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'hello.handler', code: lambda.Code.fromInline('exports.handler = {}'), }); @@ -835,4 +835,4 @@ describe('cloudtrail', () => { }); }); }); -}); \ No newline at end of file +}); diff --git a/packages/aws-cdk-lib/aws-codedeploy/test/lambda/custom-deployment-config.test.ts b/packages/aws-cdk-lib/aws-codedeploy/test/lambda/custom-deployment-config.test.ts index 3fa30560563d9..a5190fab6dc0a 100644 --- a/packages/aws-cdk-lib/aws-codedeploy/test/lambda/custom-deployment-config.test.ts +++ b/packages/aws-cdk-lib/aws-codedeploy/test/lambda/custom-deployment-config.test.ts @@ -1,7 +1,6 @@ import { testDeprecated } from '@aws-cdk/cdk-build-tools'; import { Template } from '../../../assertions'; import * as lambda from '../../../aws-lambda'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../../aws-lambda/lib/helpers-internal'; import * as cdk from '../../../core'; import * as codedeploy from '../../lib'; @@ -9,7 +8,7 @@ function mockFunction(stack: cdk.Stack, id: string) { return new lambda.Function(stack, id, { code: lambda.Code.fromInline('mock'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); } function mockAlias(stack: cdk.Stack) { diff --git a/packages/aws-cdk-lib/aws-codedeploy/test/lambda/deployment-group.test.ts b/packages/aws-cdk-lib/aws-codedeploy/test/lambda/deployment-group.test.ts index 653fd2be5c20f..f3fe863b088e1 100644 --- a/packages/aws-cdk-lib/aws-codedeploy/test/lambda/deployment-group.test.ts +++ b/packages/aws-cdk-lib/aws-codedeploy/test/lambda/deployment-group.test.ts @@ -2,7 +2,6 @@ import { Match, Template } from '../../../assertions'; import * as cloudwatch from '../../../aws-cloudwatch'; import * as iam from '../../../aws-iam'; import * as lambda from '../../../aws-lambda'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../../aws-lambda/lib/helpers-internal'; import * as cdk from '../../../core'; import { Stack } from '../../../core'; import * as codedeploy from '../../lib'; @@ -12,7 +11,7 @@ function mockFunction(stack: cdk.Stack, id: string) { return new lambda.Function(stack, id, { code: lambda.Code.fromInline('mock'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); } function mockAlias(stack: cdk.Stack) { diff --git a/packages/aws-cdk-lib/aws-codepipeline-actions/test/lambda/lambda-invoke-action.test.ts b/packages/aws-cdk-lib/aws-codepipeline-actions/test/lambda/lambda-invoke-action.test.ts index f21b7061050a7..2798fed1e27b5 100644 --- a/packages/aws-cdk-lib/aws-codepipeline-actions/test/lambda/lambda-invoke-action.test.ts +++ b/packages/aws-cdk-lib/aws-codepipeline-actions/test/lambda/lambda-invoke-action.test.ts @@ -1,7 +1,6 @@ import { Template, Match } from '../../../assertions'; import * as codepipeline from '../../../aws-codepipeline'; import * as lambda from '../../../aws-lambda'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../../aws-lambda/lib/helpers-internal'; import * as s3 from '../../../aws-s3'; import * as sns from '../../../aws-sns'; import { App, Aws, Lazy, SecretValue, Stack, Token } from '../../../core'; @@ -358,7 +357,7 @@ function stackIncludingLambdaInvokeCodePipeline(props: HelperProps, app?: App) { lambda: new lambda.Function(stack, 'Lambda', { code: lambda.Code.fromCfnParameters(), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }), userParameters: props.userParams, userParametersString: props.userParamsString, diff --git a/packages/aws-cdk-lib/aws-codepipeline-actions/test/pipeline.test.ts b/packages/aws-cdk-lib/aws-codepipeline-actions/test/pipeline.test.ts index 8d750847700bb..fac873b4ba4fd 100644 --- a/packages/aws-cdk-lib/aws-codepipeline-actions/test/pipeline.test.ts +++ b/packages/aws-cdk-lib/aws-codepipeline-actions/test/pipeline.test.ts @@ -5,7 +5,6 @@ import * as codepipeline from '../../aws-codepipeline'; import * as targets from '../../aws-events-targets'; import * as iam from '../../aws-iam'; import * as lambda from '../../aws-lambda'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; import * as s3 from '../../aws-s3'; import * as sns from '../../aws-sns'; import { App, Aws, CfnParameter, SecretValue, Stack } from '../../core'; @@ -428,7 +427,7 @@ describe('pipeline', () => { const lambdaFun = new lambda.Function(stack, 'Function', { code: new lambda.InlineCode('bla'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const pipeline = new codepipeline.Pipeline(stack, 'Pipeline'); diff --git a/packages/aws-cdk-lib/aws-cognito/test/user-pool.test.ts b/packages/aws-cdk-lib/aws-cognito/test/user-pool.test.ts index b24e2cd4b4b6b..af482b5abf1ab 100644 --- a/packages/aws-cdk-lib/aws-cognito/test/user-pool.test.ts +++ b/packages/aws-cdk-lib/aws-cognito/test/user-pool.test.ts @@ -6,7 +6,6 @@ import * as kms from '../../aws-kms'; import * as lambda from '../../aws-lambda'; import { CfnParameter, Duration, Stack, Tags } from '../../core'; import { AccountRecovery, Mfa, NumberAttribute, StringAttribute, UserPool, UserPoolIdentityProvider, UserPoolOperation, VerificationEmailStyle, UserPoolEmail, AdvancedSecurityMode } from '../lib'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; describe('User Pool', () => { test('default setup', () => { @@ -521,12 +520,12 @@ describe('User Pool', () => { const fn1 = new lambda.Function(stack, 'fn1', { code: lambda.Code.fromInline('foo'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', }); const fn2 = new lambda.Function(stack, 'fn2', { code: lambda.Code.fromInline('foo'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', }); @@ -2115,7 +2114,7 @@ function fooFunction(scope: Construct, name: string): lambda.IFunction { return new lambda.Function(scope, name, { functionName: name, code: lambda.Code.fromInline('foo'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', }); } diff --git a/packages/aws-cdk-lib/aws-events-targets/test/api-gateway/api-gateway.test.ts b/packages/aws-cdk-lib/aws-events-targets/test/api-gateway/api-gateway.test.ts index 7f8cf14ee8e73..dcd598bbfa89a 100644 --- a/packages/aws-cdk-lib/aws-events-targets/test/api-gateway/api-gateway.test.ts +++ b/packages/aws-cdk-lib/aws-events-targets/test/api-gateway/api-gateway.test.ts @@ -7,7 +7,6 @@ import * as lambda from '../../../aws-lambda'; import * as sqs from '../../../aws-sqs'; import * as cdk from '../../../core'; import * as targets from '../../lib'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../../aws-lambda/lib/helpers-internal'; test('use api gateway rest api as an event rule target', () => { // GIVEN @@ -256,7 +255,7 @@ function newTestRestApi(scope: constructs.Construct, suffix = '') { const lambdaFunctin = new lambda.Function(scope, `MyLambda${suffix}`, { code: new lambda.InlineCode('foo'), handler: 'bar', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); return new api.LambdaRestApi( scope, `MyLambdaRestApi${suffix}`, { handler: lambdaFunctin, diff --git a/packages/aws-cdk-lib/aws-lambda-destinations/test/destinations.test.ts b/packages/aws-cdk-lib/aws-lambda-destinations/test/destinations.test.ts index e9f51f184eecc..1cdac49b1e505 100644 --- a/packages/aws-cdk-lib/aws-lambda-destinations/test/destinations.test.ts +++ b/packages/aws-cdk-lib/aws-lambda-destinations/test/destinations.test.ts @@ -1,7 +1,6 @@ import { Template } from '../../assertions'; import * as events from '../../aws-events'; import * as lambda from '../../aws-lambda'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; import * as sns from '../../aws-sns'; import * as sqs from '../../aws-sqs'; import { Stack } from '../../core'; @@ -15,7 +14,7 @@ beforeEach(() => { const lambdaProps = { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }; test('event bus as destination', () => { diff --git a/packages/aws-cdk-lib/aws-lambda-event-sources/test/test-function.ts b/packages/aws-cdk-lib/aws-lambda-event-sources/test/test-function.ts index b296faffee1a4..4a55c7b55e79a 100644 --- a/packages/aws-cdk-lib/aws-lambda-event-sources/test/test-function.ts +++ b/packages/aws-cdk-lib/aws-lambda-event-sources/test/test-function.ts @@ -1,13 +1,12 @@ import * as constructs from 'constructs'; import * as lambda from '../../aws-lambda'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; export class TestFunction extends lambda.Function { constructor(scope: constructs.Construct, id: string) { super(scope, id, { handler: 'index.handler', code: lambda.Code.fromInline(`exports.handler = ${handler.toString()}`), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); } } diff --git a/packages/aws-cdk-lib/aws-lambda/lib/helpers-internal/defaults.ts b/packages/aws-cdk-lib/aws-lambda/lib/helpers-internal/defaults.ts deleted file mode 100644 index 54e1eb805b5c5..0000000000000 --- a/packages/aws-cdk-lib/aws-lambda/lib/helpers-internal/defaults.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { Runtime, RuntimeFamily } from '../runtime'; - -/** - * The preferred NodeJS runtime to use for unit tests - * - * We're centralizing these runtimes, and avoiding using any *real* `NODEJS_xx` - * runtimes, so that when it comes time to upgrade Node there are only limited places - * to changed and it will be an easy grep to figure them all out. - */ -export const DEFAULT_UNITTEST_RUNTIME = new Runtime('nodejs99.x', RuntimeFamily.NODEJS, { - supportsInlineCode: true, - supportsSnapStart: true, -}); diff --git a/packages/aws-cdk-lib/aws-lambda/lib/helpers-internal/index.ts b/packages/aws-cdk-lib/aws-lambda/lib/helpers-internal/index.ts deleted file mode 100644 index 34df3f0254a5f..0000000000000 --- a/packages/aws-cdk-lib/aws-lambda/lib/helpers-internal/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './defaults'; \ No newline at end of file diff --git a/packages/aws-cdk-lib/aws-lambda/test/adot.test.ts b/packages/aws-cdk-lib/aws-lambda/test/adot.test.ts index 62e64d29d7cda..d8e9491725f3e 100644 --- a/packages/aws-cdk-lib/aws-lambda/test/adot.test.ts +++ b/packages/aws-cdk-lib/aws-lambda/test/adot.test.ts @@ -2,7 +2,6 @@ import { Template } from '../../assertions'; import * as s3 from '../../aws-s3'; import * as cdk from '../../core'; import * as lambda from '../lib'; -import { DEFAULT_UNITTEST_RUNTIME } from '../lib/helpers-internal'; describe('ADOT Lambda Layer', () => { @@ -96,7 +95,7 @@ describe('ADOT Lambda Layer', () => { const fn = new lambda.Function(stack, 'Function', { code: new lambda.InlineCode('FooBar'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, architecture: lambda.Architecture.ARM_64, }); diff --git a/packages/aws-cdk-lib/aws-lambda/test/alias.test.ts b/packages/aws-cdk-lib/aws-lambda/test/alias.test.ts index 793455f14d7ab..34ee5d33c52bd 100644 --- a/packages/aws-cdk-lib/aws-lambda/test/alias.test.ts +++ b/packages/aws-cdk-lib/aws-lambda/test/alias.test.ts @@ -4,7 +4,6 @@ import * as appscaling from '../../aws-applicationautoscaling'; import * as cloudwatch from '../../aws-cloudwatch'; import { Lazy, Stack } from '../../core'; import * as lambda from '../lib'; -import { DEFAULT_UNITTEST_RUNTIME } from '../lib/helpers-internal'; describe('alias', () => { testDeprecated('version and aliases', () => { @@ -12,7 +11,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const version = fn.addVersion('1'); @@ -38,7 +37,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); new lambda.Alias(stack, 'Alias', { @@ -59,7 +58,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const version = fn.addVersion('NewVersion'); @@ -85,7 +84,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const version1 = fn.addVersion('1'); @@ -115,7 +114,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const pce = 5; @@ -148,7 +147,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const version = fn.currentVersion; @@ -179,7 +178,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const version = fn.currentVersion; @@ -222,7 +221,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); // WHEN: Alias provisionedConcurrencyConfig less than 0 @@ -257,7 +256,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const version = fn.currentVersion; @@ -274,7 +273,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const version = fn.currentVersion; @@ -310,7 +309,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'fn', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); // WHEN @@ -356,7 +355,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'fn', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const alias = new lambda.Alias(stack, 'Alias', { aliasName: 'prod', @@ -397,7 +396,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const alias = new lambda.Alias(stack, 'Alias', { @@ -436,7 +435,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const alias = new lambda.Alias(stack, 'Alias', { @@ -482,7 +481,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const alias = new lambda.Alias(stack, 'Alias', { @@ -512,7 +511,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const alias = new lambda.Alias(stack, 'Alias', { @@ -533,7 +532,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const alias = new lambda.Alias(stack, 'Alias', { @@ -554,7 +553,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const alias = new lambda.Alias(stack, 'Alias', { @@ -587,7 +586,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const alias = new lambda.Alias(stack, 'Alias', { @@ -612,7 +611,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const alias = new lambda.Alias(stack, 'Alias', { @@ -638,7 +637,7 @@ describe('alias', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const aliasName = 'prod'; const alias = new lambda.Alias(stack, 'Alias', { diff --git a/packages/aws-cdk-lib/aws-lambda/test/architecture.test.ts b/packages/aws-cdk-lib/aws-lambda/test/architecture.test.ts index 2378a9ab68f1e..7baf90122e268 100644 --- a/packages/aws-cdk-lib/aws-lambda/test/architecture.test.ts +++ b/packages/aws-cdk-lib/aws-lambda/test/architecture.test.ts @@ -1,7 +1,6 @@ import { App, Stack } from '../../core'; import * as lambda from '../lib'; -import { DEFAULT_UNITTEST_RUNTIME } from '../lib/helpers-internal'; describe('architecture', () => { const app = new App(); @@ -12,7 +11,7 @@ describe('architecture', () => { const testLambda = new lambda.Function(stack, 'testLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }, ); diff --git a/packages/aws-cdk-lib/aws-lambda/test/code.test.ts b/packages/aws-cdk-lib/aws-lambda/test/code.test.ts index 077d59e81aaca..a7e3e328a1c91 100644 --- a/packages/aws-cdk-lib/aws-lambda/test/code.test.ts +++ b/packages/aws-cdk-lib/aws-lambda/test/code.test.ts @@ -4,7 +4,6 @@ import * as ecr from '../../aws-ecr'; import * as cdk from '../../core'; import * as cxapi from '../../cx-api'; import * as lambda from '../lib'; -import { DEFAULT_UNITTEST_RUNTIME } from '../lib/helpers-internal'; /* eslint-disable dot-notation */ @@ -38,13 +37,13 @@ describe('code', () => { // WHEN new lambda.Function(stack, 'Func1', { handler: 'foom', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: directoryAsset, }); new lambda.Function(stack, 'Func2', { handler: 'foom', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: directoryAsset, }); @@ -66,7 +65,7 @@ describe('code', () => { // WHEN new lambda.Function(stack, 'Func1', { code: lambda.Code.fromAsset(location), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'foom', }); @@ -88,14 +87,14 @@ describe('code', () => { const stack1 = new cdk.Stack(app, 'Stack1'); new lambda.Function(stack1, 'Func', { code: asset, - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'foom', }); const stack2 = new cdk.Stack(app, 'Stack2'); expect(() => new lambda.Function(stack2, 'Func', { code: asset, - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'foom', })).toThrow(/already associated/); }); @@ -107,7 +106,7 @@ describe('code', () => { const code = new lambda.CfnParametersCode(); new lambda.Function(stack, 'Function', { code, - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', }); @@ -153,7 +152,7 @@ describe('code', () => { new lambda.Function(stack, 'Function', { code, - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', }); @@ -435,7 +434,7 @@ describe('code', () => { new lambda.Function(stack, 'Fn', { code: lambda.Code.fromDockerBuild(path.join(__dirname, 'docker-build-lambda')), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); // then @@ -461,7 +460,7 @@ describe('code', () => { imagePath: '/my/image/path', }), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); // then @@ -478,7 +477,7 @@ describe('code', () => { imagePath: '/my/image/path/', }), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); // then @@ -487,7 +486,7 @@ describe('code', () => { }); }); -function defineFunction(code: lambda.Code, runtime: lambda.Runtime = DEFAULT_UNITTEST_RUNTIME) { +function defineFunction(code: lambda.Code, runtime: lambda.Runtime = lambda.Runtime.NODEJS_LATEST) { const stack = new cdk.Stack(); return new lambda.Function(stack, 'Func', { handler: 'foom', diff --git a/packages/aws-cdk-lib/aws-lambda/test/event-source-mapping.test.ts b/packages/aws-cdk-lib/aws-lambda/test/event-source-mapping.test.ts index 2954d7793ac12..574f2604052f2 100644 --- a/packages/aws-cdk-lib/aws-lambda/test/event-source-mapping.test.ts +++ b/packages/aws-cdk-lib/aws-lambda/test/event-source-mapping.test.ts @@ -1,7 +1,6 @@ import { Match, Template } from '../../assertions'; import * as cdk from '../../core'; import { Code, EventSourceMapping, Function, Runtime, Alias, StartingPosition, FilterRule, FilterCriteria } from '../lib'; -import { DEFAULT_UNITTEST_RUNTIME } from '../lib/helpers-internal'; let stack: cdk.Stack; let fn: Function; @@ -10,7 +9,7 @@ beforeEach(() => { fn = new Function(stack, 'fn', { handler: 'index.handler', code: Code.fromInline('exports.handler = ${handler.toString()}'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); }); diff --git a/packages/aws-cdk-lib/aws-lambda/test/function-hash.test.ts b/packages/aws-cdk-lib/aws-lambda/test/function-hash.test.ts index 0a6a20730aff9..853187fb87b19 100644 --- a/packages/aws-cdk-lib/aws-lambda/test/function-hash.test.ts +++ b/packages/aws-cdk-lib/aws-lambda/test/function-hash.test.ts @@ -6,7 +6,10 @@ import { App, CfnOutput, CfnResource, Stack } from '../../core'; import * as cxapi from '../../cx-api'; import * as lambda from '../lib'; import { calculateFunctionHash, trimFromStart, VERSION_LOCKED } from '../lib/function-hash'; -import { DEFAULT_UNITTEST_RUNTIME } from '../lib/helpers-internal'; + +const THE_RUNTIME = new lambda.Runtime('nodejs99.x', lambda.RuntimeFamily.NODEJS, { + supportsInlineCode: true, +}); describe('function hash', () => { describe('trimFromStart', () => { @@ -33,20 +36,20 @@ describe('function hash', () => { }); const stack1 = new Stack(app, 'Stack1'); const fn1 = new lambda.Function(stack1, 'MyFunction1', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: THE_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'handler.zip')), handler: 'index.handler', }); const stack2 = new Stack(app, 'Stack2'); const fn2 = new lambda.Function(stack2, 'MyFunction1', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: THE_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'handler.zip')), handler: 'index.handler', }); expect(calculateFunctionHash(fn1)).toEqual(calculateFunctionHash(fn2)); - expect(calculateFunctionHash(fn1)).toEqual('4d01738cfb7a756e5d619aba2a32a875'); + expect(calculateFunctionHash(fn1)).toEqual('8339678b5b0bc177dc54bb86c6541f80'); }); }); @@ -58,13 +61,13 @@ describe('function hash', () => { }); const stack1 = new Stack(app); const fn1 = new lambda.Function(stack1, 'MyFunction1', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: THE_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'my-lambda-handler')), handler: 'index.handler', }); expect(calculateFunctionHash(fn1)).not.toEqual('74ee309e3752199288e6d64d385b52c4'); - expect(calculateFunctionHash(fn1)).toEqual('534c1c7ecc6f52586168e94ea71d370b'); + expect(calculateFunctionHash(fn1)).toEqual('9777bc13204c752e28426db2c01997ac'); }); test('environment variables impact hash', () => { @@ -75,7 +78,7 @@ describe('function hash', () => { }); const stack1 = new Stack(app, 'Stack1'); const fn1 = new lambda.Function(stack1, 'MyFunction', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: THE_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'my-lambda-handler')), handler: 'index.handler', environment: { @@ -85,7 +88,7 @@ describe('function hash', () => { const stack2 = new Stack(app); const fn2 = new lambda.Function(stack2, 'MyFunction', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: THE_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'my-lambda-handler')), handler: 'index.handler', environment: { @@ -93,7 +96,7 @@ describe('function hash', () => { }, }); - expect(calculateFunctionHash(fn1)).toEqual('75b6358cef620177cff294ed8e0286ab'); + expect(calculateFunctionHash(fn1)).toEqual('d5df63ad7377cf03dd0f49c60c6f0fc1'); expect(calculateFunctionHash(fn2)).toEqual('11c06ba9d7b70ad28b8d48183bad18e9'); }); @@ -105,7 +108,7 @@ describe('function hash', () => { }); const stack1 = new Stack(app, 'Stack1'); const fn1 = new lambda.Function(stack1, 'MyFunction', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: THE_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'my-lambda-handler')), handler: 'index.handler', environment: { @@ -115,7 +118,7 @@ describe('function hash', () => { const stack2 = new Stack(app); const fn2 = new lambda.Function(stack2, 'MyFunction', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: THE_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'my-lambda-handler')), handler: 'index.handler', environment: { @@ -123,26 +126,26 @@ describe('function hash', () => { }, }); - expect(calculateFunctionHash(fn1)).toEqual('75b6358cef620177cff294ed8e0286ab'); + expect(calculateFunctionHash(fn1)).toEqual('d5df63ad7377cf03dd0f49c60c6f0fc1'); expect(calculateFunctionHash(fn2)).toEqual('11c06ba9d7b70ad28b8d48183bad18e9'); }); test('inline code change impacts the hash', () => { const stack1 = new Stack(); const fn1 = new lambda.Function(stack1, 'MyFunction', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: THE_RUNTIME, code: lambda.Code.fromInline('foo'), handler: 'index.handler', }); const stack2 = new Stack(); const fn2 = new lambda.Function(stack2, 'MyFunction', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: THE_RUNTIME, code: lambda.Code.fromInline('foo bar'), handler: 'index.handler', }); - expect(calculateFunctionHash(fn1)).toEqual('55e50858f6b564bc4745996ce85ee3a6'); + expect(calculateFunctionHash(fn1)).toEqual('e6e08236949a28be9ade77a2323e8391'); expect(calculateFunctionHash(fn2)).toEqual('6e144e45237f91e92a8f0c757baa7251'); }); @@ -154,13 +157,13 @@ describe('function hash', () => { stack1 = new Stack(); layer1 = new lambda.LayerVersion(stack1, 'MyLayer', { code: lambda.Code.fromAsset(path.join(__dirname, 'layer-code')), - compatibleRuntimes: [DEFAULT_UNITTEST_RUNTIME], + compatibleRuntimes: [THE_RUNTIME], license: 'Apache-2.0', description: 'A layer to test the L2 construct', }); layer2 = new lambda.LayerVersion(stack1, 'MyLayer2', { code: lambda.Code.fromAsset(path.join(__dirname, 'layer-code')), - compatibleRuntimes: [DEFAULT_UNITTEST_RUNTIME], + compatibleRuntimes: [THE_RUNTIME], license: 'Apache-2.0', description: 'A layer to test the L2 construct', }); @@ -169,7 +172,7 @@ describe('function hash', () => { test('same configuration yields the same hash', () => { const stack2 = new Stack(); const fn1 = new lambda.Function(stack2, 'MyFunction', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: THE_RUNTIME, code: lambda.Code.fromInline('foo'), handler: 'index.handler', layers: [layer1], @@ -177,20 +180,20 @@ describe('function hash', () => { const stack3 = new Stack(); const fn2 = new lambda.Function(stack3, 'MyFunction', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: THE_RUNTIME, code: lambda.Code.fromInline('foo'), handler: 'index.handler', layers: [layer1], }); expect(calculateFunctionHash(fn1)).toEqual(calculateFunctionHash(fn2)); - expect(calculateFunctionHash(fn1)).toEqual('d08113bb99431d6edb7dd7306196c691'); + expect(calculateFunctionHash(fn1)).toEqual('3b500cb399914c341ec5c39ef3bd182c'); }); test('different layers impacts hash', () => { const stack2 = new Stack(); const fn1 = new lambda.Function(stack2, 'MyFunction', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: THE_RUNTIME, code: lambda.Code.fromInline('foo'), handler: 'index.handler', layers: [layer1], @@ -198,13 +201,13 @@ describe('function hash', () => { const stack3 = new Stack(); const fn2 = new lambda.Function(stack3, 'MyFunction', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: THE_RUNTIME, code: lambda.Code.fromInline('foo'), handler: 'index.handler', layers: [layer2], }); - expect(calculateFunctionHash(fn1)).toEqual('d08113bb99431d6edb7dd7306196c691'); + expect(calculateFunctionHash(fn1)).toEqual('3b500cb399914c341ec5c39ef3bd182c'); expect(calculateFunctionHash(fn2)).toEqual('e5b139e844ae371180cdeec538c5dbb1'); }); @@ -212,7 +215,7 @@ describe('function hash', () => { test('without feature flag, preserve old behavior to avoid unnecessary invalidation of templates', () => { const stack2 = new Stack(); const fn1 = new lambda.Function(stack2, 'MyFunction', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: THE_RUNTIME, code: lambda.Code.fromInline('foo'), handler: 'index.handler', layers: [layer1, layer2], @@ -220,13 +223,13 @@ describe('function hash', () => { const stack3 = new Stack(); const fn2 = new lambda.Function(stack3, 'MyFunction', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: THE_RUNTIME, code: lambda.Code.fromInline('foo'), handler: 'index.handler', layers: [layer2, layer1], }); - expect(calculateFunctionHash(fn1)).toEqual('8c452c65bf5d5ad220d25525d591f500'); + expect(calculateFunctionHash(fn1)).toEqual('443ca997f1a9bb2ff4378f44cab76f67'); expect(calculateFunctionHash(fn2)).toEqual('37a4fec56aae4ff2d69fd2c23a0b5804'); }); @@ -235,7 +238,7 @@ describe('function hash', () => { const stack2 = new Stack(app, 'stack2'); const fn1 = new lambda.Function(stack2, 'MyFunction', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: THE_RUNTIME, code: lambda.Code.fromInline('foo'), handler: 'index.handler', layers: [layer1, layer2], @@ -243,7 +246,7 @@ describe('function hash', () => { const stack3 = new Stack(app, 'stack3'); const fn2 = new lambda.Function(stack3, 'MyFunction', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: THE_RUNTIME, code: lambda.Code.fromInline('foo'), handler: 'index.handler', layers: [layer2, layer1], @@ -259,7 +262,7 @@ describe('function hash', () => { const stack2 = new Stack(app, 'stack2'); const importedLayer1 = lambda.LayerVersion.fromLayerVersionArn(stack2, 'imported-layer', 'arn:aws:lambda:::layer::'); const fn1 = new lambda.Function(stack2, 'MyFunction', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: THE_RUNTIME, code: lambda.Code.fromInline('foo'), handler: 'index.handler', layers: [importedLayer1], @@ -268,7 +271,7 @@ describe('function hash', () => { const stack3 = new Stack(app, 'stack3'); const importedLayer2 = lambda.LayerVersion.fromLayerVersionArn(stack3, 'imported-layer', 'arn:aws:lambda:::layer::'); const fn2 = new lambda.Function(stack3, 'MyFunction', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: THE_RUNTIME, code: lambda.Code.fromInline('foo'), handler: 'index.handler', layers: [importedLayer2], @@ -282,7 +285,7 @@ describe('function hash', () => { test('without "currentVersion", we preserve old behavior to avoid unnecessary invalidation of templates', () => { const stack1 = new Stack(); const fn1 = new lambda.Function(stack1, 'MyFunction', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: THE_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'my-lambda-handler')), handler: 'index.handler', environment: { @@ -293,7 +296,7 @@ describe('function hash', () => { const stack2 = new Stack(); const fn2 = new lambda.Function(stack2, 'MyFunction', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: THE_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'my-lambda-handler')), handler: 'index.handler', environment: { @@ -308,7 +311,7 @@ describe('function hash', () => { test('with "currentVersion", we sort env keys so order is consistent', () => { const stack1 = new Stack(); const fn1 = new lambda.Function(stack1, 'MyFunction', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: THE_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'my-lambda-handler')), handler: 'index.handler', environment: { @@ -321,7 +324,7 @@ describe('function hash', () => { const stack2 = new Stack(); const fn2 = new lambda.Function(stack2, 'MyFunction', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: THE_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'my-lambda-handler')), handler: 'index.handler', environment: { @@ -350,14 +353,14 @@ describe('function hash', () => { test('DependsOn does not impact function hash', () => { const stack1 = new Stack(app, 'Stack1'); const fn1 = new lambda.Function(stack1, 'MyFunction1', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: THE_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'handler.zip')), handler: 'index.handler', }); const stack2 = new Stack(app, 'Stack2'); const fn2 = new lambda.Function(stack2, 'MyFunction1', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: THE_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'handler.zip')), handler: 'index.handler', }); @@ -369,21 +372,21 @@ describe('function hash', () => { }); fn2.node.addDependency(res); - expect(calculateFunctionHash(fn1)).toEqual('4d01738cfb7a756e5d619aba2a32a875'); + expect(calculateFunctionHash(fn1)).toEqual('8339678b5b0bc177dc54bb86c6541f80'); expect(calculateFunctionHash(fn1)).toEqual(calculateFunctionHash(fn2)); }); test('properties not locked to the version do not impact function hash', () => { const stack1 = new Stack(app, 'Stack1'); const fn1 = new lambda.Function(stack1, 'MyFunction', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: THE_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'handler.zip')), handler: 'index.handler', }); const stack2 = new Stack(app, 'Stack2'); const fn2 = new lambda.Function(stack2, 'MyFunction', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: THE_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'handler.zip')), handler: 'index.handler', @@ -397,7 +400,7 @@ describe('function hash', () => { test('unclassified property throws an error', () => { const stack = new Stack(app); const fn1 = new lambda.Function(stack, 'MyFunction1', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: THE_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'handler.zip')), handler: 'index.handler', }); @@ -409,7 +412,7 @@ describe('function hash', () => { test('manual classification as version locked', () => { const stack = new Stack(app); const fn1 = new lambda.Function(stack, 'MyFunction1', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: THE_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'handler.zip')), handler: 'index.handler', }); @@ -423,7 +426,7 @@ describe('function hash', () => { test('manual classification as not version locked', () => { const stack = new Stack(app); const fn1 = new lambda.Function(stack, 'MyFunction1', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: THE_RUNTIME, code: lambda.Code.fromAsset(path.join(__dirname, 'handler.zip')), handler: 'index.handler', }); diff --git a/packages/aws-cdk-lib/aws-lambda/test/function-url.test.ts b/packages/aws-cdk-lib/aws-lambda/test/function-url.test.ts index e43cdf6e543ca..048fcea4fa1fa 100644 --- a/packages/aws-cdk-lib/aws-lambda/test/function-url.test.ts +++ b/packages/aws-cdk-lib/aws-lambda/test/function-url.test.ts @@ -2,7 +2,6 @@ import { Template } from '../../assertions'; import * as iam from '../../aws-iam'; import * as cdk from '../../core'; import * as lambda from '../lib'; -import { DEFAULT_UNITTEST_RUNTIME } from '../lib/helpers-internal'; describe('FunctionUrl', () => { test('default function url', () => { @@ -11,7 +10,7 @@ describe('FunctionUrl', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); // WHEN @@ -37,7 +36,7 @@ describe('FunctionUrl', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); // WHEN @@ -95,7 +94,7 @@ describe('FunctionUrl', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const aliasName = 'prod'; const alias = new lambda.Alias(stack, 'Alias', { @@ -125,7 +124,7 @@ describe('FunctionUrl', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const version = new lambda.Version(stack, 'Version', { lambda: fn, @@ -147,7 +146,7 @@ describe('FunctionUrl', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); // WHEN @@ -170,7 +169,7 @@ describe('FunctionUrl', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const fnUrl = new lambda.FunctionUrl(stack, 'FunctionUrl', { function: fn, diff --git a/packages/aws-cdk-lib/aws-lambda/test/function.test.ts b/packages/aws-cdk-lib/aws-lambda/test/function.test.ts index 72d6c983d6d6f..109b199870c70 100644 --- a/packages/aws-cdk-lib/aws-lambda/test/function.test.ts +++ b/packages/aws-cdk-lib/aws-lambda/test/function.test.ts @@ -19,7 +19,6 @@ import * as cxapi from '../../cx-api'; import * as lambda from '../lib'; import { AdotLambdaLayerJavaSdkVersion } from '../lib/adot-layers'; import { calculateFunctionHash } from '../lib/function-hash'; -import { DEFAULT_UNITTEST_RUNTIME } from '../lib/helpers-internal'; describe('function', () => { const dockerLambdaHandlerPath = path.join(__dirname, 'docker-lambda-handler'); @@ -29,7 +28,7 @@ describe('function', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); Template.fromStack(stack).hasResourceProperties('AWS::IAM::Role', { @@ -53,7 +52,7 @@ describe('function', () => { Code: { ZipFile: 'foo' }, Handler: 'index.handler', Role: { 'Fn::GetAtt': ['MyLambdaServiceRole4539ECB6', 'Arn'] }, - Runtime: 'nodejs99.x', + Runtime: lambda.Runtime.NODEJS_LATEST.name, }, DependsOn: ['MyLambdaServiceRole4539ECB6'], }); @@ -64,7 +63,7 @@ describe('function', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, initialPolicy: [new iam.PolicyStatement({ actions: ['*'], resources: ['*'] })], }); Template.fromStack(stack).hasResourceProperties('AWS::IAM::Role', { @@ -106,7 +105,7 @@ describe('function', () => { Code: { ZipFile: 'foo' }, Handler: 'index.handler', Role: { 'Fn::GetAtt': ['MyLambdaServiceRole4539ECB6', 'Arn'] }, - Runtime: 'nodejs99.x', + Runtime: lambda.Runtime.NODEJS_LATEST.name, }, DependsOn: ['MyLambdaServiceRoleDefaultPolicy5BBC6F68', 'MyLambdaServiceRole4539ECB6'], }); @@ -742,7 +741,7 @@ describe('function', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, functionName: 'OneFunctionToRuleThemAll', deadLetterQueueEnabled: true, }); @@ -810,7 +809,7 @@ describe('function', () => { 'Arn', ], }, - Runtime: 'nodejs99.x', + Runtime: lambda.Runtime.NODEJS_LATEST.name, DeadLetterConfig: { TargetArn: { 'Fn::GetAtt': [ @@ -834,7 +833,7 @@ describe('function', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, deadLetterQueueEnabled: true, }); @@ -860,7 +859,7 @@ describe('function', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, deadLetterQueueEnabled: false, }); @@ -875,7 +874,7 @@ describe('function', () => { 'Arn', ], }, - Runtime: 'nodejs99.x', + Runtime: lambda.Runtime.NODEJS_LATEST.name, }); }); @@ -890,7 +889,7 @@ describe('function', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, deadLetterQueue: dlQueue, }); @@ -935,7 +934,7 @@ describe('function', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, deadLetterQueueEnabled: true, deadLetterQueue: dlQueue, }); @@ -981,7 +980,7 @@ describe('function', () => { expect(() => new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, deadLetterQueueEnabled: false, deadLetterQueue: dlQueue, })).toThrow(/deadLetterQueue defined but deadLetterQueueEnabled explicitly set to false/); @@ -995,7 +994,7 @@ describe('function', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, deadLetterTopic: dlTopic, }); @@ -1030,7 +1029,7 @@ describe('function', () => { expect(() => new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, deadLetterQueueEnabled: false, deadLetterTopic: dlTopic, })).toThrow(/deadLetterQueue and deadLetterTopic cannot be specified together at the same time/); @@ -1044,7 +1043,7 @@ describe('function', () => { expect(() => new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, deadLetterQueueEnabled: true, deadLetterTopic: dlTopic, })).toThrow(/deadLetterQueue and deadLetterTopic cannot be specified together at the same time/); @@ -1059,7 +1058,7 @@ describe('function', () => { expect(() => new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, deadLetterQueue: dlQueue, deadLetterTopic: dlTopic, })).toThrow(/deadLetterQueue and deadLetterTopic cannot be specified together at the same time/); @@ -1071,7 +1070,7 @@ describe('function', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, tracing: lambda.Tracing.ACTIVE, }); @@ -1109,7 +1108,7 @@ describe('function', () => { 'Arn', ], }, - Runtime: 'nodejs99.x', + Runtime: lambda.Runtime.NODEJS_LATEST.name, TracingConfig: { Mode: 'Active', }, @@ -1127,7 +1126,7 @@ describe('function', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, tracing: lambda.Tracing.PASS_THROUGH, }); @@ -1165,7 +1164,7 @@ describe('function', () => { 'Arn', ], }, - Runtime: 'nodejs99.x', + Runtime: lambda.Runtime.NODEJS_LATEST.name, TracingConfig: { Mode: 'PassThrough', }, @@ -1183,7 +1182,7 @@ describe('function', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, tracing: lambda.Tracing.DISABLED, }); @@ -1201,7 +1200,7 @@ describe('function', () => { 'Arn', ], }, - Runtime: 'nodejs99.x', + Runtime: lambda.Runtime.NODEJS_LATEST.name, }, DependsOn: [ 'MyLambdaServiceRole4539ECB6', @@ -1235,7 +1234,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'Function', { code: lambda.Code.fromInline('xxx'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); // WHEN @@ -1265,7 +1264,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'Function', { code: lambda.Code.fromInline('xxx'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const service = new iam.ServicePrincipal('apigateway.amazonaws.com'); @@ -1291,7 +1290,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'Function', { code: lambda.Code.fromInline('xxx'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const account = new iam.AccountPrincipal('123456789012'); @@ -1317,7 +1316,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'Function', { code: lambda.Code.fromInline('xxx'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const account = new iam.ArnPrincipal('arn:aws:iam::123456789012:role/someRole'); @@ -1343,7 +1342,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'Function', { code: lambda.Code.fromInline('xxx'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const org = new iam.OrganizationPrincipal('my-org-id'); @@ -1370,7 +1369,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'Function', { code: lambda.Code.fromInline('xxx'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const service = new iam.ServicePrincipal('elasticloadbalancing.amazonaws.com'); @@ -1399,7 +1398,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'Function', { code: lambda.Code.fromInline('xxx'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); // WHEN @@ -1431,7 +1430,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'Function', { code: lambda.Code.fromInline('xxx'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); // WHEN @@ -1532,7 +1531,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'Function', { code: lambda.Code.fromInline('xxx'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); // THEN @@ -1551,7 +1550,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'Function', { code: lambda.Code.fromInline('xxx'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); let bindTarget; @@ -1576,7 +1575,7 @@ describe('function', () => { const code = new lambda.S3Code(bucket, 'ObjectKey'); const fn = new lambda.Function(stack, 'fn', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromInline('exports.main = function() { console.log("DONE"); }'), handler: 'index.main', }); @@ -1586,7 +1585,7 @@ describe('function', () => { // WHEN const layer = new lambda.LayerVersion(stack, 'LayerVersion', { code, - compatibleRuntimes: [DEFAULT_UNITTEST_RUNTIME], + compatibleRuntimes: [lambda.Runtime.NODEJS_LATEST], }); fn.addLayers(layer); @@ -1604,12 +1603,12 @@ describe('function', () => { const code = new lambda.S3Code(bucket, 'ObjectKey'); const layer = new lambda.LayerVersion(stack, 'LayerVersion', { code, - compatibleRuntimes: [DEFAULT_UNITTEST_RUNTIME], + compatibleRuntimes: [lambda.Runtime.NODEJS_LATEST], }); // function with layer const fn = new lambda.Function(stack, 'fn', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromInline('exports.main = function() { console.log("DONE"); }'), handler: 'index.main', layers: [layer], @@ -1643,7 +1642,9 @@ describe('function', () => { // THEN expect(() => new lambda.Function(stack, 'Function', { layers: [layer], - runtime: new lambda.Runtime('something1'), + runtime: new lambda.Runtime('something1', lambda.RuntimeFamily.NODEJS, { + supportsInlineCode: true, + }), code: lambda.Code.fromInline('exports.main = function() { console.log("DONE"); }'), handler: 'index.main', })).toThrow(/something1 is not in \[something2\]/); @@ -1654,13 +1655,13 @@ describe('function', () => { const stack = new cdk.Stack(undefined, 'TestStack'); const layers = new Array(6).fill(lambda.LayerVersion.fromLayerVersionAttributes(stack, 'TestLayer', { layerVersionArn: 'arn:aws:...', - compatibleRuntimes: [DEFAULT_UNITTEST_RUNTIME], + compatibleRuntimes: [lambda.Runtime.NODEJS_LATEST], })); // THEN expect(() => new lambda.Function(stack, 'Function', { layers, - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromInline('exports.main = function() { console.log("DONE"); }'), handler: 'index.main', })).toThrow(/Unable to add layer:/); @@ -1744,7 +1745,7 @@ describe('function', () => { // WHEN new lambda.Function(stack, 'fn', { code: lambda.Code.fromInline('boom'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.bam', events: [ new EventSource(), @@ -1820,7 +1821,7 @@ describe('function', () => { new lambda.Function(stack, 'fn', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, onFailure: { bind: () => ({ destination: 'on-failure-arn' }), }, @@ -1856,7 +1857,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'fn', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, maxEventAge: cdk.Duration.hours(1), }); @@ -1890,7 +1891,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'fn', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); // WHEN @@ -1919,7 +1920,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'fn', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); fn.addEnvironment('KEY', 'value', { removeInEdge: true }); @@ -1938,7 +1939,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'fn', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, environment: { KEY: 'value', }, @@ -2021,7 +2022,7 @@ describe('function', () => { // WHEN/THEN expect(() => new lambda.Function(stack, 'fn', { handler: 'foo', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromInline(''), })).toThrow(/Lambda inline code cannot be empty/); }); @@ -2030,7 +2031,7 @@ describe('function', () => { const stack = new cdk.Stack(); const fn = new lambda.Function(stack, 'fn', { handler: 'foo', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromInline('foo'), }); const logGroup = fn.logGroup; @@ -2048,7 +2049,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'fn', { handler: 'foo', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromInline('foo'), deadLetterQueue: dlQueue, }); @@ -2070,7 +2071,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'fn', { handler: 'foo', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromInline('foo'), deadLetterTopic: dlTopic, }); @@ -2087,7 +2088,7 @@ describe('function', () => { const stack = new cdk.Stack(); const fn = new lambda.Function(stack, 'fn', { handler: 'foo', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromInline('foo'), deadLetterQueueEnabled: true, }); @@ -2104,7 +2105,7 @@ describe('function', () => { const stack = new cdk.Stack(); const fn = new lambda.Function(stack, 'fn', { handler: 'foo', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromInline('foo'), }); const deadLetterQueue = fn.deadLetterQueue; @@ -2118,7 +2119,7 @@ describe('function', () => { const stack = new cdk.Stack(); const fn = new lambda.Function(stack, 'fn', { handler: 'foo', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromInline('foo'), logRetention: logs.RetentionDays.FIVE_DAYS, }); @@ -2145,7 +2146,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const version1 = fn.latestVersion; @@ -2173,7 +2174,7 @@ describe('function', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, environment: { SOME: 'Variable', }, @@ -2364,7 +2365,7 @@ describe('function', () => { expect(() => new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, profilingGroup: new ProfilingGroup(stack, 'ProfilingGroup'), environment: { AWS_CODEGURU_PROFILER_GROUP_ARN: 'profiler_group_arn', @@ -2382,7 +2383,7 @@ describe('function', () => { // WHEN const { timeout } = new lambda.Function(stack, 'MyFunction', { handler: 'foo', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromAsset(path.join(__dirname, 'handler.zip')), timeout: cdk.Duration.minutes(2), }); @@ -2398,7 +2399,7 @@ describe('function', () => { // WHEN const { timeout } = new lambda.Function(stack, 'MyFunction', { handler: 'foo', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromAsset(path.join(__dirname, 'handler.zip')), }); @@ -2414,7 +2415,7 @@ describe('function', () => { const stack1 = new cdk.Stack(); const fn1 = new lambda.Function(stack1, 'MyFunction', { handler: 'foo', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromAsset(path.join(__dirname, 'handler.zip')), environment: { FOO: 'bar', @@ -2423,7 +2424,7 @@ describe('function', () => { const stack2 = new cdk.Stack(); const fn2 = new lambda.Function(stack2, 'MyFunction', { handler: 'foo', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromAsset(path.join(__dirname, 'handler.zip')), environment: { FOO: 'bear', @@ -2467,7 +2468,7 @@ describe('function', () => { new lambda.Function(stack, 'MyFunction', { vpc, handler: 'foo', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromAsset(path.join(__dirname, 'handler.zip')), filesystem: lambda.FileSystem.fromEfsAccessPoint(accessPoint, '/mnt/msg'), }); @@ -2522,7 +2523,7 @@ describe('function', () => { expect(() => { new lambda.Function(stack, 'MyFunction', { handler: 'foo', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromAsset(path.join(__dirname, 'handler.zip')), filesystem: lambda.FileSystem.fromEfsAccessPoint(accessPoint, '/mnt/msg'), }); @@ -2550,7 +2551,7 @@ describe('function', () => { vpc, handler: 'foo', securityGroups: [securityGroup], - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromAsset(path.join(__dirname, 'handler.zip')), filesystem: lambda.FileSystem.fromEfsAccessPoint(accessPoint, '/mnt/msg'), }); @@ -2714,7 +2715,7 @@ describe('function', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, codeSigningConfig, }); @@ -2748,7 +2749,7 @@ describe('function', () => { const stack = new cdk.Stack(); new lambda.Function(stack, 'MyFunction', { code: lambda.Code.fromInline('foo'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', architectures: [lambda.Architecture.ARM_64], @@ -2763,7 +2764,7 @@ describe('function', () => { const stack = new cdk.Stack(); new lambda.Function(stack, 'MyFunction', { code: lambda.Code.fromInline('foo'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', architecture: lambda.Architecture.ARM_64, @@ -2778,7 +2779,7 @@ describe('function', () => { const stack = new cdk.Stack(); expect(() => new lambda.Function(stack, 'MyFunction', { code: lambda.Code.fromInline('foo'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', architecture: lambda.Architecture.ARM_64, @@ -2790,7 +2791,7 @@ describe('function', () => { const stack = new cdk.Stack(); expect(() => new lambda.Function(stack, 'MyFunction', { code: lambda.Code.fromInline('foo'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', architectures: [lambda.Architecture.X86_64, lambda.Architecture.ARM_64], @@ -2801,7 +2802,7 @@ describe('function', () => { const stack = new cdk.Stack(); const fn = new lambda.Function(stack, 'MyFunction', { code: lambda.Code.fromInline('foo'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', architecture: lambda.Architecture.ARM_64, }); @@ -2812,7 +2813,7 @@ describe('function', () => { const stack = new cdk.Stack(); expect(() => new lambda.Function(stack, 'MyFunction', { code: lambda.Code.fromInline('foo'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', functionName: 'a'.repeat(65), })).toThrow(/Function name can not be longer than 64 characters/); @@ -2825,7 +2826,7 @@ describe('function', () => { new lambda.Function(stack, `foo${invalidChar}`, { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, functionName: `foo${invalidChar}`, }); }).toThrow(/can contain only letters, numbers, hyphens, or underscores with no spaces./); @@ -2841,7 +2842,7 @@ describe('function', () => { new lambda.Function(stack, 'foo', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, functionName: tokenizedFunctionName, }); }).not.toThrow(); @@ -2851,7 +2852,7 @@ describe('function', () => { const stack = new cdk.Stack(); expect(() => new lambda.Function(stack, 'MyFunction', { code: lambda.Code.fromInline('foo'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', description: 'a'.repeat(257), })).toThrow(/Function description can not be longer than 256 characters/); @@ -2866,7 +2867,7 @@ describe('function', () => { new lambda.Function(stack, 'foo', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, description: tokenizedFunctionDescription, }); }).not.toThrow(); @@ -2879,7 +2880,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); // WHEN @@ -2903,7 +2904,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); // WHEN @@ -2952,7 +2953,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); fn.addFunctionUrl(); @@ -3094,7 +3095,7 @@ describe('function', () => { const fn = new lambda.Function(stack, 'Function', { code: lambda.Code.fromInline('xxx'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const sourceArnA = 'some-arn-a'; const sourceArnB = 'some-arn-b'; @@ -3168,7 +3169,7 @@ describe('function', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, adotInstrumentation: { layerVersion: lambda.AdotLayerVersion.fromJavaSdkLayerVersion(AdotLambdaLayerJavaSdkVersion.V1_28_1), execWrapper: lambda.AdotLambdaExecWrapper.REGULAR_HANDLER, @@ -3255,7 +3256,7 @@ test('throws if ephemeral storage size is out of bound', () => { expect(() => new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'bar', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, ephemeralStorageSize: Size.mebibytes(511), })).toThrow(/Ephemeral storage size must be between 512 and 10240 MB/); }); @@ -3265,7 +3266,7 @@ test('set ephemeral storage to desired size', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'bar', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, ephemeralStorageSize: Size.mebibytes(1024), }); @@ -3274,7 +3275,7 @@ test('set ephemeral storage to desired size', () => { { Code: { ZipFile: 'foo' }, Handler: 'bar', - Runtime: 'nodejs99.x', + Runtime: lambda.Runtime.NODEJS_LATEST.name, EphemeralStorage: { Size: 1024, }, @@ -3288,7 +3289,7 @@ test('ephemeral storage allows unresolved tokens', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'bar', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, ephemeralStorageSize: Size.mebibytes(Lazy.number({ produce: () => 1024 })), }); }).not.toThrow(); @@ -3300,7 +3301,7 @@ test('FunctionVersionUpgrade adds new description to function', () => { new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('foo'), handler: 'bar', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, description: 'my description', }); @@ -3311,7 +3312,7 @@ test('FunctionVersionUpgrade adds new description to function', () => { { Code: { ZipFile: 'foo' }, Handler: 'bar', - Runtime: 'nodejs99.x', + Runtime: lambda.Runtime.NODEJS_LATEST.name, Description: Match.stringLikeRegexp('my description version-hash'), }, }); @@ -3342,7 +3343,7 @@ test('test 2.87.0 version hash stability', () => { const layer = new lambda.LayerVersion(stack, 'MyLayer', { code: lambda.Code.fromAsset(path.join(__dirname, 'x.zip')), compatibleRuntimes: [ - DEFAULT_UNITTEST_RUNTIME, + lambda.Runtime.NODEJS_LATEST, ], }); @@ -3355,7 +3356,7 @@ test('test 2.87.0 version hash stability', () => { }); const lambdaFn = new lambda.Function(stack, 'MyLambda', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, memorySize: 128, handler: 'index.handler', timeout: cdk.Duration.seconds(30), @@ -3383,7 +3384,7 @@ test('test 2.87.0 version hash stability', () => { Properties: { FunctionVersion: { 'Fn::GetAtt': [ - 'MyLambdaCurrentVersionE7A382CCd55a48b26bd9a860d8842137f2243c37', + 'MyLambdaCurrentVersionE7A382CCf807e688af4b50b3d420129f528d7d1d', 'Version', ], }, diff --git a/packages/aws-cdk-lib/aws-lambda/test/lambda-insights.test.ts b/packages/aws-cdk-lib/aws-lambda/test/lambda-insights.test.ts index 424f3e1709bd3..44261dadccef8 100644 --- a/packages/aws-cdk-lib/aws-lambda/test/lambda-insights.test.ts +++ b/packages/aws-cdk-lib/aws-lambda/test/lambda-insights.test.ts @@ -17,7 +17,7 @@ function functionWithInsightsVersion( functionName: id, code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, architecture, insightsVersion, }); diff --git a/packages/aws-cdk-lib/aws-lambda/test/lambda-version.test.ts b/packages/aws-cdk-lib/aws-lambda/test/lambda-version.test.ts index 220da2737410a..0051c4ea2fce1 100644 --- a/packages/aws-cdk-lib/aws-lambda/test/lambda-version.test.ts +++ b/packages/aws-cdk-lib/aws-lambda/test/lambda-version.test.ts @@ -2,7 +2,6 @@ import { testDeprecated } from '@aws-cdk/cdk-build-tools'; import { Template } from '../../assertions'; import * as cdk from '../../core'; import * as lambda from '../lib'; -import { DEFAULT_UNITTEST_RUNTIME } from '../lib/helpers-internal'; describe('lambda version', () => { test('can import a Lambda version by ARN', () => { @@ -32,7 +31,7 @@ describe('lambda version', () => { // GIVEN const stack = new cdk.Stack(); const fn = new lambda.Function(stack, 'Fn', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', code: lambda.Code.fromInline('foo'), }); @@ -64,7 +63,7 @@ describe('lambda version', () => { // GIVEN const stack = new cdk.Stack(); const fn = new lambda.Function(stack, 'Fn', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', code: lambda.Code.fromInline('foo'), }); @@ -109,7 +108,7 @@ describe('lambda version', () => { // GIVEN const stack = new cdk.Stack(); const fn = new lambda.Function(stack, 'Fn', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', code: lambda.Code.fromInline('foo'), }); @@ -137,7 +136,7 @@ describe('lambda version', () => { // GIVEN const stack = new cdk.Stack(); const fn = new lambda.Function(stack, 'Fn', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', code: lambda.Code.fromInline('foo'), }); @@ -161,7 +160,7 @@ describe('lambda version', () => { const app = new cdk.App(); const stack = new cdk.Stack(app, 'Stack'); const fn = new lambda.Function(stack, 'Fn', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', code: lambda.Code.fromInline('foo'), }); @@ -169,7 +168,7 @@ describe('lambda version', () => { // WHEN new lambda.Function(stack, 'OtherFn', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', code: lambda.Code.fromInline('foo'), environment: { @@ -190,7 +189,7 @@ describe('lambda version', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const version = new lambda.Version(stack, 'Version', { lambda: fn, diff --git a/packages/aws-cdk-lib/aws-lambda/test/layers.test.ts b/packages/aws-cdk-lib/aws-lambda/test/layers.test.ts index 5d5bfb69716b8..47386596cebe2 100644 --- a/packages/aws-cdk-lib/aws-lambda/test/layers.test.ts +++ b/packages/aws-cdk-lib/aws-lambda/test/layers.test.ts @@ -4,7 +4,6 @@ import * as s3 from '../../aws-s3'; import * as cdk from '../../core'; import * as cxapi from '../../cx-api'; import * as lambda from '../lib'; -import { DEFAULT_UNITTEST_RUNTIME } from '../lib/helpers-internal'; describe('layers', () => { test('creating a layer', () => { @@ -16,7 +15,7 @@ describe('layers', () => { // WHEN new lambda.LayerVersion(stack, 'LayerVersion', { code, - compatibleRuntimes: [DEFAULT_UNITTEST_RUNTIME], + compatibleRuntimes: [lambda.Runtime.NODEJS_LATEST], }); // THEN @@ -25,7 +24,7 @@ describe('layers', () => { S3Bucket: stack.resolve(bucket.bucketName), S3Key: 'ObjectKey', }, - CompatibleRuntimes: ['nodejs99.x'], + CompatibleRuntimes: [lambda.Runtime.NODEJS_LATEST.name], }); }); @@ -36,7 +35,7 @@ describe('layers', () => { const code = new lambda.S3Code(bucket, 'ObjectKey'); const layer = new lambda.LayerVersion(stack, 'LayerVersion', { code, - compatibleRuntimes: [DEFAULT_UNITTEST_RUNTIME], + compatibleRuntimes: [lambda.Runtime.NODEJS_LATEST], }); // WHEN diff --git a/packages/aws-cdk-lib/aws-lambda/test/singleton-lambda.test.ts b/packages/aws-cdk-lib/aws-lambda/test/singleton-lambda.test.ts index 8c0fea611fd5a..5ac20fd33c6b1 100644 --- a/packages/aws-cdk-lib/aws-lambda/test/singleton-lambda.test.ts +++ b/packages/aws-cdk-lib/aws-lambda/test/singleton-lambda.test.ts @@ -5,7 +5,6 @@ import * as iam from '../../aws-iam'; import * as s3 from '../../aws-s3'; import * as cdk from '../../core'; import * as lambda from '../lib'; -import { DEFAULT_UNITTEST_RUNTIME } from '../lib/helpers-internal'; describe('singleton lambda', () => { test('can add same singleton Lambda multiple times, only instantiated once in template', () => { @@ -249,7 +248,7 @@ describe('singleton lambda', () => { const singleton = new lambda.SingletonFunction(stack, 'Singleton', { uuid: '84c0de93-353f-4217-9b0b-45b6c993251a', code: new lambda.InlineCode('foo'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', }); @@ -277,7 +276,7 @@ describe('singleton lambda', () => { const singleton = new lambda.SingletonFunction(stack, 'Singleton', { uuid: '84c0de93-353f-4217-9b0b-45b6c993251a', code: new lambda.InlineCode('foo'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', securityGroups: [securityGroup], vpc: vpc, diff --git a/packages/aws-cdk-lib/aws-lambda/test/vpc-lambda.test.ts b/packages/aws-cdk-lib/aws-lambda/test/vpc-lambda.test.ts index aea49e172daaf..973531aae6588 100644 --- a/packages/aws-cdk-lib/aws-lambda/test/vpc-lambda.test.ts +++ b/packages/aws-cdk-lib/aws-lambda/test/vpc-lambda.test.ts @@ -3,7 +3,6 @@ import { Template } from '../../assertions'; import * as ec2 from '../../aws-ec2'; import * as cdk from '../../core'; import * as lambda from '../lib'; -import { DEFAULT_UNITTEST_RUNTIME } from '../lib/helpers-internal'; describe('lambda + vpc', () => { describe('lambda in vpc', () => { @@ -22,7 +21,7 @@ describe('lambda + vpc', () => { fn = new lambda.Function(stack, 'Lambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, vpc: vpc, allowAllOutbound: false, }); @@ -48,7 +47,7 @@ describe('lambda + vpc', () => { new lambda.Function(stack, 'LambdaWithCustomSG', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, vpc, securityGroup: new ec2.SecurityGroup(stack, 'CustomSecurityGroupX', { vpc }), }); @@ -71,7 +70,7 @@ describe('lambda + vpc', () => { new lambda.Function(stack, 'LambdaWithCustomSGList', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, vpc, securityGroups: [ new ec2.SecurityGroup(stack, 'CustomSecurityGroupA', { vpc }), @@ -99,7 +98,7 @@ describe('lambda + vpc', () => { new lambda.Function(stack, 'LambdaWithWrongProps', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, vpc, securityGroup: new ec2.SecurityGroup(stack, 'CustomSecurityGroupB', { vpc }), securityGroups: [ @@ -190,7 +189,7 @@ describe('lambda + vpc', () => { const lambdaFn = new lambda.Function(stack, 'Lambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); // WHEN @@ -209,7 +208,7 @@ describe('lambda + vpc', () => { allowPublicSubnet: true, code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, vpc, vpcSubnets: { subnetType: ec2.SubnetType.PUBLIC }, }); @@ -237,7 +236,7 @@ describe('lambda + vpc', () => { new lambda.Function(stack, 'PrivateLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, vpc, vpcSubnets: { subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS }, }); @@ -273,7 +272,7 @@ describe('lambda + vpc', () => { new lambda.Function(stack, 'IsolatedLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, vpc, vpcSubnets: { subnetType: ec2.SubnetType.PRIVATE_ISOLATED }, }); @@ -318,7 +317,7 @@ describe('lambda + vpc', () => { new lambda.Function(stack, 'PublicLambda', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, vpc, vpcSubnets: { subnetType: ec2.SubnetType.PUBLIC }, }); @@ -334,7 +333,7 @@ describe('lambda + vpc', () => { new lambda.Function(stack, 'Function', { code: new lambda.InlineCode('foo'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, vpcSubnets: { subnetType: ec2.SubnetType.PRIVATE }, }); }).toThrow('Cannot configure \'vpcSubnets\' without configuring a VPC'); diff --git a/packages/aws-cdk-lib/aws-logs-destinations/test/lambda.test.ts b/packages/aws-cdk-lib/aws-logs-destinations/test/lambda.test.ts index 91d592263d73c..e69de29bb2d1d 100644 --- a/packages/aws-cdk-lib/aws-logs-destinations/test/lambda.test.ts +++ b/packages/aws-cdk-lib/aws-logs-destinations/test/lambda.test.ts @@ -1,107 +0,0 @@ -import { Template } from '../../assertions'; -import * as lambda from '../../aws-lambda'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; -import * as logs from '../../aws-logs'; -import * as cdk from '../../core'; -import * as dests from '../lib'; - -let stack: cdk.Stack; -let fn: lambda.Function; -let logGroup: logs.LogGroup; - -beforeEach(() => { - // GIVEN - stack = new cdk.Stack(); - fn = new lambda.Function(stack, 'MyLambda', { - code: new lambda.InlineCode('foo'), - handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, - }); - logGroup = new logs.LogGroup(stack, 'LogGroup'); -}); - -test('lambda can be used as metric subscription destination', () => { - // WHEN - new logs.SubscriptionFilter(stack, 'Subscription', { - logGroup, - destination: new dests.LambdaDestination(fn), - filterPattern: logs.FilterPattern.allEvents(), - }); - - // THEN: subscription target is Lambda - Template.fromStack(stack).hasResourceProperties('AWS::Logs::SubscriptionFilter', { - DestinationArn: { 'Fn::GetAtt': ['MyLambdaCCE802FB', 'Arn'] }, - }); - - // THEN: Lambda has permissions to be invoked by CWL - Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Permission', { - Action: 'lambda:InvokeFunction', - FunctionName: { 'Fn::GetAtt': ['MyLambdaCCE802FB', 'Arn'] }, - Principal: 'logs.amazonaws.com', - }); -}); - -test('can have multiple subscriptions use the same Lambda', () => { - // WHEN - new logs.SubscriptionFilter(stack, 'Subscription', { - logGroup, - destination: new dests.LambdaDestination(fn), - filterPattern: logs.FilterPattern.allEvents(), - }); - - new logs.SubscriptionFilter(stack, 'Subscription2', { - logGroup: new logs.LogGroup(stack, 'LG2'), - destination: new dests.LambdaDestination(fn), - filterPattern: logs.FilterPattern.allEvents(), - }); - - // THEN: Lambda has permissions to be invoked by CWL from both Source Arns - Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Permission', { - Action: 'lambda:InvokeFunction', - FunctionName: { 'Fn::GetAtt': ['MyLambdaCCE802FB', 'Arn'] }, - SourceArn: { 'Fn::GetAtt': ['LogGroupF5B46931', 'Arn'] }, - Principal: 'logs.amazonaws.com', - }); - - Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Permission', { - Action: 'lambda:InvokeFunction', - FunctionName: { 'Fn::GetAtt': ['MyLambdaCCE802FB', 'Arn'] }, - SourceArn: { 'Fn::GetAtt': ['LG224A94C8F', 'Arn'] }, - Principal: 'logs.amazonaws.com', - }); -}); - -test('lambda permissions are not added when addPermissions is false', () => { - // WHEN - new logs.SubscriptionFilter(stack, 'Subscription', { - logGroup, - destination: new dests.LambdaDestination(fn, { addPermissions: false }), - filterPattern: logs.FilterPattern.allEvents(), - }); - - // THEN: subscription target is Lambda - Template.fromStack(stack).hasResourceProperties('AWS::Logs::SubscriptionFilter', { - DestinationArn: { 'Fn::GetAtt': ['MyLambdaCCE802FB', 'Arn'] }, - }); - - // THEN: Lambda does not have permissions to be invoked by CWL - expect(Template.fromStack(stack).findResources('AWS::Lambda::Permission', { - Action: 'lambda:InvokeFunction', - FunctionName: { 'Fn::GetAtt': ['MyLambdaCCE802FB', 'Arn'] }, - Principal: 'logs.amazonaws.com', - })).toEqual({}); -}); - -test('subscription depends on lambda\'s permission', () => { - // WHEN - new logs.SubscriptionFilter(stack, 'Subscription', { - logGroup, - destination: new dests.LambdaDestination(fn), - filterPattern: logs.FilterPattern.allEvents(), - }); - - // THEN: Subscription filter depends on Lambda's Permission - Template.fromStack(stack).hasResource('AWS::Logs::SubscriptionFilter', { - DependsOn: ['SubscriptionCanInvokeLambdaD31DEAD2'], - }); -}); diff --git a/packages/aws-cdk-lib/aws-rds/test/instance.test.ts b/packages/aws-cdk-lib/aws-rds/test/instance.test.ts index a66e0b17ed859..3e791f2a0ab81 100644 --- a/packages/aws-cdk-lib/aws-rds/test/instance.test.ts +++ b/packages/aws-cdk-lib/aws-rds/test/instance.test.ts @@ -4,7 +4,6 @@ import * as targets from '../../aws-events-targets'; import { ManagedPolicy, Role, ServicePrincipal, AccountPrincipal } from '../../aws-iam'; import * as kms from '../../aws-kms'; import * as lambda from '../../aws-lambda'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; import * as logs from '../../aws-logs'; import * as s3 from '../../aws-s3'; import * as cdk from '../../core'; @@ -532,7 +531,7 @@ describe('instance', () => { const fn = new lambda.Function(stack, 'Function', { code: lambda.Code.fromInline('dummy'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); // WHEN diff --git a/packages/aws-cdk-lib/aws-s3-deployment/test/content.test.ts b/packages/aws-cdk-lib/aws-s3-deployment/test/content.test.ts index 8fcfbc1292a35..858f6afd9a394 100644 --- a/packages/aws-cdk-lib/aws-s3-deployment/test/content.test.ts +++ b/packages/aws-cdk-lib/aws-s3-deployment/test/content.test.ts @@ -1,5 +1,4 @@ import * as lambda from '../../aws-lambda'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; import * as s3 from '../../aws-s3'; import { Lazy, Stack } from '../../core'; import { Source } from '../lib'; @@ -85,7 +84,7 @@ test('json-encoded string', () => { test('markers are returned in the source config', () => { const stack = new Stack(); - const handler = new lambda.Function(stack, 'Handler', { runtime: DEFAULT_UNITTEST_RUNTIME, code: lambda.Code.fromInline('foo'), handler: 'index.handler' }); + const handler = new lambda.Function(stack, 'Handler', { runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromInline('foo'), handler: 'index.handler' }); const actual = Source.data('file1.txt', `boom-${stack.account}`).bind(stack, { handlerRole: handler.role! }); expect(actual.markers).toStrictEqual({ '<>': { Ref: 'AWS::AccountId' }, @@ -120,4 +119,4 @@ test('lazy string which resolves to something with a deploy-time value', () => { markers: { }, }); -}); \ No newline at end of file +}); diff --git a/packages/aws-cdk-lib/aws-s3-notifications/test/lambda/lambda.test.ts b/packages/aws-cdk-lib/aws-s3-notifications/test/lambda/lambda.test.ts index aca061dbb4ee1..4d1342c4ba7e3 100644 --- a/packages/aws-cdk-lib/aws-s3-notifications/test/lambda/lambda.test.ts +++ b/packages/aws-cdk-lib/aws-s3-notifications/test/lambda/lambda.test.ts @@ -1,6 +1,5 @@ import { Match, Template } from '../../../assertions'; import * as lambda from '../../../aws-lambda'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../../aws-lambda/lib/helpers-internal'; import * as s3 from '../../../aws-s3'; import { Stack, App } from '../../../core'; import * as s3n from '../../lib'; @@ -10,13 +9,13 @@ test('add notifications to multiple functions', () => { const stack = new Stack(); const bucket = new s3.Bucket(stack, 'MyBucket'); const fn1 = new lambda.Function(stack, 'MyFunction1', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', code: lambda.Code.fromInline('foo'), }); const fn2 = new lambda.Function(stack, 'MyFunction2', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', code: lambda.Code.fromInline('foo'), }); @@ -81,7 +80,7 @@ test('lambda in a different stack as notification target', () => { const lambdaFunction = new lambda.Function(lambdaStack, 'lambdaFunction', { code: lambda.Code.fromInline('whatever'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); const bucket = new s3.Bucket(bucketStack, 'bucket'); @@ -122,7 +121,7 @@ test('lambda as notification target', () => { const stack = new Stack(); const bucketA = new s3.Bucket(stack, 'MyBucket'); const fn = new lambda.Function(stack, 'MyFunction', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', code: lambda.Code.fromInline('foo'), }); @@ -189,7 +188,7 @@ test('permissions are added as a dependency to the notifications resource when u const bucket = new s3.Bucket(stack, 'MyBucket'); const fn = new lambda.SingletonFunction(stack, 'MyFunction', { uuid: 'uuid', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', code: lambda.Code.fromInline('foo'), }); @@ -209,7 +208,7 @@ test('add multiple event notifications using a singleton function', () => { const bucket = new s3.Bucket(stack, 'MyBucket'); const fn = new lambda.SingletonFunction(stack, 'MyFunction', { uuid: 'uuid', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', code: lambda.Code.fromInline('foo'), }); diff --git a/packages/aws-cdk-lib/aws-secretsmanager/test/rotation-schedule.test.ts b/packages/aws-cdk-lib/aws-secretsmanager/test/rotation-schedule.test.ts index 5ae60c2356190..d406b8830dda1 100644 --- a/packages/aws-cdk-lib/aws-secretsmanager/test/rotation-schedule.test.ts +++ b/packages/aws-cdk-lib/aws-secretsmanager/test/rotation-schedule.test.ts @@ -2,7 +2,6 @@ import { Match, Template } from '../../assertions'; import * as ec2 from '../../aws-ec2'; import * as kms from '../../aws-kms'; import * as lambda from '../../aws-lambda'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; import * as cdk from '../../core'; import { Duration } from '../../core'; import * as secretsmanager from '../lib'; @@ -16,7 +15,7 @@ test('create a rotation schedule with a rotation Lambda', () => { // GIVEN const secret = new secretsmanager.Secret(stack, 'Secret'); const rotationLambda = new lambda.Function(stack, 'Lambda', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromInline('export.handler = event => event;'), handler: 'index.handler', }); @@ -48,7 +47,7 @@ test('create a rotation schedule without immediate rotation', () => { // GIVEN const secret = new secretsmanager.Secret(stack, 'Secret'); const rotationLambda = new lambda.Function(stack, 'Lambda', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromInline('export.handler = event => event;'), handler: 'index.handler', }); @@ -76,7 +75,7 @@ test('assign permissions for rotation schedule with a rotation Lambda', () => { // GIVEN const secret = new secretsmanager.Secret(stack, 'Secret'); const rotationLambda = new lambda.Function(stack, 'Lambda', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromInline('export.handler = event => event;'), handler: 'index.handler', }); @@ -135,7 +134,7 @@ test('grants correct permissions for secret imported by name', () => { // GIVEN const secret = secretsmanager.Secret.fromSecretNameV2(stack, 'Secret', 'mySecretName'); const rotationLambda = new lambda.Function(stack, 'Lambda', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromInline('export.handler = event => event;'), handler: 'index.handler', }); @@ -187,7 +186,7 @@ test('assign kms permissions for rotation schedule with a rotation Lambda', () = const encryptionKey = new kms.Key(stack, 'Key'); const secret = new secretsmanager.Secret(stack, 'Secret', { encryptionKey }); const rotationLambda = new lambda.Function(stack, 'Lambda', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromInline('export.handler = event => event;'), handler: 'index.handler', }); @@ -599,7 +598,7 @@ describe('manual rotations', () => { const localStack = new cdk.Stack(); const secret = new secretsmanager.Secret(localStack, 'Secret'); const rotationLambda = new lambda.Function(localStack, 'Lambda', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromInline('export.handler = event => event;'), handler: 'index.handler', }); diff --git a/packages/aws-cdk-lib/aws-secretsmanager/test/secret.test.ts b/packages/aws-cdk-lib/aws-secretsmanager/test/secret.test.ts index bf917381cb90e..38ed48e3fbf55 100644 --- a/packages/aws-cdk-lib/aws-secretsmanager/test/secret.test.ts +++ b/packages/aws-cdk-lib/aws-secretsmanager/test/secret.test.ts @@ -5,7 +5,6 @@ import * as kms from '../../aws-kms'; import * as lambda from '../../aws-lambda'; import * as cdk from '../../core'; import * as secretsmanager from '../lib'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; let app: cdk.App; let stack: cdk.Stack; @@ -1178,7 +1177,7 @@ test('add a rotation schedule to an attached secret', () => { }), }); const rotationLambda = new lambda.Function(stack, 'Lambda', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromInline('export.handler = event => event;'), handler: 'index.handler', }); diff --git a/packages/aws-cdk-lib/aws-ses-actions/test/actions.test.ts b/packages/aws-cdk-lib/aws-ses-actions/test/actions.test.ts index 85d4b65786b17..f53bf29a2306b 100644 --- a/packages/aws-cdk-lib/aws-ses-actions/test/actions.test.ts +++ b/packages/aws-cdk-lib/aws-ses-actions/test/actions.test.ts @@ -85,7 +85,7 @@ test('add lambda action', () => { const fn = new lambda.Function(stack, 'Function', { code: lambda.Code.fromInline('boom'), handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); rule.addAction(new actions.Lambda({ diff --git a/packages/aws-cdk-lib/aws-sns-subscriptions/test/subs.test.ts b/packages/aws-cdk-lib/aws-sns-subscriptions/test/subs.test.ts index 585c3343ab899..d4d6998fb6fcf 100644 --- a/packages/aws-cdk-lib/aws-sns-subscriptions/test/subs.test.ts +++ b/packages/aws-cdk-lib/aws-sns-subscriptions/test/subs.test.ts @@ -1,7 +1,6 @@ import { Template } from '../../assertions'; import * as kms from '../../aws-kms'; import * as lambda from '../../aws-lambda'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; import * as sns from '../../aws-sns'; import * as sqs from '../../aws-sqs'; import { App, CfnParameter, Duration, RemovalPolicy, Stack, Token } from '../../core'; @@ -1236,7 +1235,7 @@ test('importing SQS queue and specify this as subscription', () => { test('lambda subscription', () => { const func = new lambda.Function(stack, 'MyFunc', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', code: lambda.Code.fromInline('exports.handler = function(e, c, cb) { return cb() }'), }); @@ -1296,7 +1295,7 @@ test('lambda subscription', () => { 'Arn', ], }, - 'Runtime': 'nodejs99.x', + 'Runtime': lambda.Runtime.NODEJS_LATEST.name, }, 'DependsOn': [ 'MyFuncServiceRole54065130', @@ -1347,7 +1346,7 @@ test('lambda subscription, cross region env agnostic', () => { displayName: 'displayName', }); const func = new lambda.Function(lambdaStack, 'MyFunc', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', code: lambda.Code.fromInline('exports.handler = function(e, c, cb) { return cb() }'), }); @@ -1400,7 +1399,7 @@ test('lambda subscription, cross region env agnostic', () => { ], }, 'Handler': 'index.handler', - 'Runtime': 'nodejs99.x', + 'Runtime': lambda.Runtime.NODEJS_LATEST.name, }, 'DependsOn': [ 'MyFuncServiceRole54065130', @@ -1461,7 +1460,7 @@ test('lambda subscription, cross region', () => { displayName: 'displayName', }); const func = new lambda.Function(lambdaStack, 'MyFunc', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', code: lambda.Code.fromInline('exports.handler = function(e, c, cb) { return cb() }'), }); @@ -1514,7 +1513,7 @@ test('lambda subscription, cross region', () => { ], }, 'Handler': 'index.handler', - 'Runtime': 'nodejs99.x', + 'Runtime': lambda.Runtime.NODEJS_LATEST.name, }, 'DependsOn': [ 'MyFuncServiceRole54065130', @@ -1747,7 +1746,7 @@ test('email and url subscriptions with unresolved - four subscriptions', () => { test('multiple subscriptions', () => { const queue = new sqs.Queue(stack, 'MyQueue'); const func = new lambda.Function(stack, 'MyFunc', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', code: lambda.Code.fromInline('exports.handler = function(e, c, cb) { return cb() }'), }); @@ -1863,7 +1862,7 @@ test('multiple subscriptions', () => { 'Arn', ], }, - 'Runtime': 'nodejs99.x', + 'Runtime': lambda.Runtime.NODEJS_LATEST.name, }, 'DependsOn': [ 'MyFuncServiceRole54065130', @@ -1915,7 +1914,7 @@ test('throws with mutliple subscriptions of the same subscriber', () => { test('with filter policy', () => { const func = new lambda.Function(stack, 'MyFunc', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', code: lambda.Code.fromInline('exports.handler = function(e, c, cb) { return cb() }'), }); @@ -1970,7 +1969,7 @@ test('with filter policy', () => { test('with filter policy scope MessageBody', () => { const func = new lambda.Function(stack, 'MyFunc', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', code: lambda.Code.fromInline('exports.handler = function(e, c, cb) { return cb() }'), }); @@ -2041,7 +2040,7 @@ test('region property on an imported topic as a parameter - sqs', () => { test('region property is present on an imported topic - lambda', () => { const imported = sns.Topic.fromTopicArn(stack, 'mytopic', 'arn:aws:sns:us-east-1:1234567890:mytopic'); const func = new lambda.Function(stack, 'MyFunc', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', code: lambda.Code.fromInline('exports.handler = function(e, c, cb) { return cb() }'), }); @@ -2056,7 +2055,7 @@ test('region property on an imported topic as a parameter - lambda', () => { const topicArn = new CfnParameter(stack, 'topicArn'); const imported = sns.Topic.fromTopicArn(stack, 'mytopic', topicArn.valueAsString); const func = new lambda.Function(stack, 'MyFunc', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', code: lambda.Code.fromInline('exports.handler = function(e, c, cb) { return cb() }'), }); diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/lambda/invoke.test.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/lambda/invoke.test.ts index 9789dbb68229f..8b62fe0c6024d 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/lambda/invoke.test.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/test/lambda/invoke.test.ts @@ -3,7 +3,6 @@ import * as lambda from '../../../aws-lambda'; import * as sfn from '../../../aws-stepfunctions'; import { Stack } from '../../../core'; import { LambdaInvocationType, LambdaInvoke } from '../../lib'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../../aws-lambda/lib/helpers-internal'; /* eslint-disable quote-props */ @@ -18,7 +17,7 @@ describe('LambdaInvoke', () => { lambdaFunction = new lambda.Function(stack, 'Fn', { code: lambda.Code.fromInline('foo'), handler: 'handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); }); diff --git a/packages/aws-cdk-lib/custom-resources/test/provider-framework/provider.test.ts b/packages/aws-cdk-lib/custom-resources/test/provider-framework/provider.test.ts index fb9aa99f4dcfc..cedc800fd0b68 100644 --- a/packages/aws-cdk-lib/custom-resources/test/provider-framework/provider.test.ts +++ b/packages/aws-cdk-lib/custom-resources/test/provider-framework/provider.test.ts @@ -8,7 +8,6 @@ import * as logs from '../../../aws-logs'; import { Duration, Stack } from '../../../core'; import * as cr from '../../lib'; import * as util from '../../lib/provider-framework/util'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../../aws-lambda/lib/helpers-internal'; test('security groups are applied to all framework functions', () => { @@ -23,12 +22,12 @@ test('security groups are applied to all framework functions', () => { onEventHandler: new lambda.Function(stack, 'OnEvent', { code: lambda.Code.fromInline('foo'), handler: 'index.onEvent', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }), isCompleteHandler: new lambda.Function(stack, 'IsComplete', { code: lambda.Code.fromInline('foo'), handler: 'index.isComplete', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }), vpc: vpc, vpcSubnets: { subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS }, @@ -91,12 +90,12 @@ test('vpc is applied to all framework functions', () => { onEventHandler: new lambda.Function(stack, 'OnEvent', { code: lambda.Code.fromInline('foo'), handler: 'index.onEvent', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }), isCompleteHandler: new lambda.Function(stack, 'IsComplete', { code: lambda.Code.fromInline('foo'), handler: 'index.isComplete', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }), vpc: vpc, vpcSubnets: { subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS }, @@ -143,7 +142,7 @@ test('minimal setup', () => { onEventHandler: new lambda.Function(stack, 'MyHandler', { code: lambda.Code.fromAsset(path.join(__dirname, './integration-test-fixtures/s3-file-handler')), handler: 'index.onEvent', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }), }); @@ -175,7 +174,7 @@ test('if isComplete is specified, the isComplete framework handler is also inclu const handler = new lambda.Function(stack, 'MyHandler', { code: lambda.Code.fromAsset(path.join(__dirname, './integration-test-fixtures/s3-file-handler')), handler: 'index.onEvent', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); // WHEN @@ -249,7 +248,7 @@ test('fails if "queryInterval" and/or "totalTimeout" are set without "isComplete const handler = new lambda.Function(stack, 'MyHandler', { code: lambda.Code.fromAsset(path.join(__dirname, './integration-test-fixtures/s3-file-handler')), handler: 'index.onEvent', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }); // THEN @@ -305,7 +304,7 @@ describe('log retention', () => { onEventHandler: new lambda.Function(stack, 'MyHandler', { code: lambda.Code.fromAsset(path.join(__dirname, './integration-test-fixtures/s3-file-handler')), handler: 'index.onEvent', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }), logRetention: logs.RetentionDays.ONE_WEEK, }); @@ -336,7 +335,7 @@ describe('log retention', () => { onEventHandler: new lambda.Function(stack, 'MyHandler', { code: lambda.Code.fromAsset(path.join(__dirname, './integration-test-fixtures/s3-file-handler')), handler: 'index.onEvent', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }), }); @@ -355,7 +354,7 @@ describe('role', () => { onEventHandler: new lambda.Function(stack, 'MyHandler', { code: lambda.Code.fromAsset(path.join(__dirname, './integration-test-fixtures/s3-file-handler')), handler: 'index.onEvent', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }), role: new iam.Role(stack, 'MyRole', { assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'), @@ -383,7 +382,7 @@ describe('role', () => { onEventHandler: new lambda.Function(stack, 'MyHandler', { code: lambda.Code.fromAsset(path.join(__dirname, './integration-test-fixtures/s3-file-handler')), handler: 'index.onEvent', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }), }); @@ -410,7 +409,7 @@ describe('name', () => { onEventHandler: new lambda.Function(stack, 'MyHandler', { code: lambda.Code.fromAsset(path.join(__dirname, './integration-test-fixtures/s3-file-handler')), handler: 'index.onEvent', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }), providerFunctionName, }); @@ -435,7 +434,7 @@ describe('environment encryption', () => { onEventHandler: new lambda.Function(stack, 'MyHandler', { code: lambda.Code.fromAsset(path.join(__dirname, './integration-test-fixtures/s3-file-handler')), handler: 'index.onEvent', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, }), providerFunctionEnvEncryption: key, }); diff --git a/packages/aws-cdk-lib/custom-resources/test/provider-framework/waiter-state-machine.test.ts b/packages/aws-cdk-lib/custom-resources/test/provider-framework/waiter-state-machine.test.ts index 3a413db61afd9..9181c8b54dae7 100644 --- a/packages/aws-cdk-lib/custom-resources/test/provider-framework/waiter-state-machine.test.ts +++ b/packages/aws-cdk-lib/custom-resources/test/provider-framework/waiter-state-machine.test.ts @@ -3,7 +3,6 @@ import { Template } from '../../../assertions'; import { Code, Function as lambdaFn, Runtime } from '../../../aws-lambda'; import { Duration, Stack } from '../../../core'; import { WaiterStateMachine } from '../../lib/provider-framework/waiter-state-machine'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../../aws-lambda/lib/helpers-internal'; describe('state machine', () => { test('contains the needed resources', () => { @@ -13,12 +12,12 @@ describe('state machine', () => { const isCompleteHandler = new lambdaFn(stack, 'isComplete', { code: Code.fromInline('foo'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', }); const timeoutHandler = new lambdaFn(stack, 'isTimeout', { code: Code.fromInline('foo'), - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, handler: 'index.handler', }); const interval = Duration.hours(2); @@ -97,4 +96,4 @@ describe('state machine', () => { Roles: [{ Ref: roleId }], }); }); -}); \ No newline at end of file +}); diff --git a/packages/aws-cdk-lib/package.json b/packages/aws-cdk-lib/package.json index 63179e2ba0d92..d889036470f82 100644 --- a/packages/aws-cdk-lib/package.json +++ b/packages/aws-cdk-lib/package.json @@ -363,7 +363,6 @@ "./aws-kms": "./aws-kms/index.js", "./aws-lakeformation": "./aws-lakeformation/index.js", "./aws-lambda": "./aws-lambda/index.js", - "./aws-lambda/lib/helpers-internal": "./aws-lambda/lib/helpers-internal/index.js", "./aws-lambda-destinations": "./aws-lambda-destinations/index.js", "./aws-lambda-event-sources": "./aws-lambda-event-sources/index.js", "./aws-lambda-nodejs": "./aws-lambda-nodejs/index.js", diff --git a/packages/aws-cdk-lib/triggers/test/triggers.test.ts b/packages/aws-cdk-lib/triggers/test/triggers.test.ts index f80259c9ee27a..bd012f1ae0484 100644 --- a/packages/aws-cdk-lib/triggers/test/triggers.test.ts +++ b/packages/aws-cdk-lib/triggers/test/triggers.test.ts @@ -1,6 +1,5 @@ import { Template } from '../../assertions'; import * as lambda from '../../aws-lambda'; -import { DEFAULT_UNITTEST_RUNTIME } from '../../aws-lambda/lib/helpers-internal'; import * as sns from '../../aws-sns'; import { Duration, Stack } from '../../core'; import * as triggers from '../lib'; @@ -12,7 +11,7 @@ test('minimal trigger function', () => { // WHEN new triggers.TriggerFunction(stack, 'MyTrigger', { handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromInline('foo'), }); @@ -34,7 +33,7 @@ test('before/after', () => { // WHEN const myTrigger = new triggers.TriggerFunction(stack, 'MyTrigger', { - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromInline('zoo'), handler: 'index.handler', @@ -74,13 +73,13 @@ test('multiple functions', () => { // WHEN new triggers.TriggerFunction(stack, 'MyTrigger', { handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromInline('foo'), }); new triggers.TriggerFunction(stack, 'MySecondTrigger', { handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromInline('bar'), }); @@ -96,7 +95,7 @@ test('minimal trigger', () => { const stack = new Stack(); const func = new lambda.Function(stack, 'MyFunction', { handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromInline('foo'), }); @@ -119,7 +118,7 @@ test('trigger with optional properties', () => { const stack = new Stack(); const func = new lambda.Function(stack, 'MyFunction', { handler: 'index.handler', - runtime: DEFAULT_UNITTEST_RUNTIME, + runtime: lambda.Runtime.NODEJS_LATEST, code: lambda.Code.fromInline('foo'), }); From ad687b7cbf4155f511bb3fb4b43779f60f8ab735 Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Tue, 5 Sep 2023 15:44:20 +0200 Subject: [PATCH 3/6] tests --- .../aws-cloudtrail/test/cloudtrail.test.ts | 1 - .../test/event-source-mapping.test.ts | 1 + .../aws-lambda/test/function-hash.test.ts | 10 +- .../aws-lambda/test/function.test.ts | 7 +- .../aws-lambda/test/lambda-version.test.ts | 22 ++-- .../aws-logs-destinations/test/lambda.test.ts | 106 ++++++++++++++++++ .../waiter-state-machine.test.ts | 3 +- .../triggers/test/triggers.test.ts | 22 ++-- 8 files changed, 144 insertions(+), 28 deletions(-) diff --git a/packages/aws-cdk-lib/aws-cloudtrail/test/cloudtrail.test.ts b/packages/aws-cdk-lib/aws-cloudtrail/test/cloudtrail.test.ts index 785806fdc80db..0950d68c185cc 100644 --- a/packages/aws-cdk-lib/aws-cloudtrail/test/cloudtrail.test.ts +++ b/packages/aws-cdk-lib/aws-cloudtrail/test/cloudtrail.test.ts @@ -8,7 +8,6 @@ import * as s3 from '../../aws-s3'; import * as sns from '../../aws-sns'; import { Stack } from '../../core'; import { ManagementEventSources, ReadWriteType, Trail, InsightType } from '../lib'; -import { lambda.Runtime.NODEJS_LATEST } from '../../aws-lambda/lib/helpers-internal'; const ExpectedBucketPolicyProperties = { PolicyDocument: { diff --git a/packages/aws-cdk-lib/aws-lambda/test/event-source-mapping.test.ts b/packages/aws-cdk-lib/aws-lambda/test/event-source-mapping.test.ts index 574f2604052f2..2a5e15046bfd6 100644 --- a/packages/aws-cdk-lib/aws-lambda/test/event-source-mapping.test.ts +++ b/packages/aws-cdk-lib/aws-lambda/test/event-source-mapping.test.ts @@ -1,5 +1,6 @@ import { Match, Template } from '../../assertions'; import * as cdk from '../../core'; +import * as lambda from '../lib'; import { Code, EventSourceMapping, Function, Runtime, Alias, StartingPosition, FilterRule, FilterCriteria } from '../lib'; let stack: cdk.Stack; diff --git a/packages/aws-cdk-lib/aws-lambda/test/function-hash.test.ts b/packages/aws-cdk-lib/aws-lambda/test/function-hash.test.ts index 853187fb87b19..a54e6106f0b49 100644 --- a/packages/aws-cdk-lib/aws-lambda/test/function-hash.test.ts +++ b/packages/aws-cdk-lib/aws-lambda/test/function-hash.test.ts @@ -97,7 +97,7 @@ describe('function hash', () => { }); expect(calculateFunctionHash(fn1)).toEqual('d5df63ad7377cf03dd0f49c60c6f0fc1'); - expect(calculateFunctionHash(fn2)).toEqual('11c06ba9d7b70ad28b8d48183bad18e9'); + expect(calculateFunctionHash(fn2)).toEqual('6ca1f12d5210d52fe5e5d8933cd29634'); }); test('runtime impacts hash', () => { @@ -127,7 +127,7 @@ describe('function hash', () => { }); expect(calculateFunctionHash(fn1)).toEqual('d5df63ad7377cf03dd0f49c60c6f0fc1'); - expect(calculateFunctionHash(fn2)).toEqual('11c06ba9d7b70ad28b8d48183bad18e9'); + expect(calculateFunctionHash(fn2)).toEqual('6ca1f12d5210d52fe5e5d8933cd29634'); }); test('inline code change impacts the hash', () => { @@ -146,7 +146,7 @@ describe('function hash', () => { }); expect(calculateFunctionHash(fn1)).toEqual('e6e08236949a28be9ade77a2323e8391'); - expect(calculateFunctionHash(fn2)).toEqual('6e144e45237f91e92a8f0c757baa7251'); + expect(calculateFunctionHash(fn2)).toEqual('48e10e13160453b41f24975434c2d3f3'); }); describe('lambda layers', () => { @@ -208,7 +208,7 @@ describe('function hash', () => { }); expect(calculateFunctionHash(fn1)).toEqual('3b500cb399914c341ec5c39ef3bd182c'); - expect(calculateFunctionHash(fn2)).toEqual('e5b139e844ae371180cdeec538c5dbb1'); + expect(calculateFunctionHash(fn2)).toEqual('aec62de1c572402fe8e75ca60c9fd96f'); }); describe('impact of lambda layer order on hash', () => { @@ -230,7 +230,7 @@ describe('function hash', () => { }); expect(calculateFunctionHash(fn1)).toEqual('443ca997f1a9bb2ff4378f44cab76f67'); - expect(calculateFunctionHash(fn2)).toEqual('37a4fec56aae4ff2d69fd2c23a0b5804'); + expect(calculateFunctionHash(fn2)).toEqual('2330cb52a944876c13cd69f5947415cd'); }); test('with feature flag, we sort layers so order is consistent', () => { diff --git a/packages/aws-cdk-lib/aws-lambda/test/function.test.ts b/packages/aws-cdk-lib/aws-lambda/test/function.test.ts index 109b199870c70..8e2f0a297f238 100644 --- a/packages/aws-cdk-lib/aws-lambda/test/function.test.ts +++ b/packages/aws-cdk-lib/aws-lambda/test/function.test.ts @@ -3331,6 +3331,7 @@ test('function using a reserved environment variable', () => { }); test('test 2.87.0 version hash stability', () => { + const theRuntime = new lambda.Runtime('node99.x'); // GIVEN const app = new cdk.App({ context: { @@ -3343,7 +3344,7 @@ test('test 2.87.0 version hash stability', () => { const layer = new lambda.LayerVersion(stack, 'MyLayer', { code: lambda.Code.fromAsset(path.join(__dirname, 'x.zip')), compatibleRuntimes: [ - lambda.Runtime.NODEJS_LATEST, + theRuntime, ], }); @@ -3356,7 +3357,7 @@ test('test 2.87.0 version hash stability', () => { }); const lambdaFn = new lambda.Function(stack, 'MyLambda', { - runtime: lambda.Runtime.NODEJS_LATEST, + runtime: theRuntime, memorySize: 128, handler: 'index.handler', timeout: cdk.Duration.seconds(30), @@ -3384,7 +3385,7 @@ test('test 2.87.0 version hash stability', () => { Properties: { FunctionVersion: { 'Fn::GetAtt': [ - 'MyLambdaCurrentVersionE7A382CCf807e688af4b50b3d420129f528d7d1d', + 'MyLambdaCurrentVersionE7A382CC36ba24a5a2aa206296d3e383129fd83a', 'Version', ], }, diff --git a/packages/aws-cdk-lib/aws-lambda/test/lambda-version.test.ts b/packages/aws-cdk-lib/aws-lambda/test/lambda-version.test.ts index 0051c4ea2fce1..6236a92df5dae 100644 --- a/packages/aws-cdk-lib/aws-lambda/test/lambda-version.test.ts +++ b/packages/aws-cdk-lib/aws-lambda/test/lambda-version.test.ts @@ -3,6 +3,10 @@ import { Template } from '../../assertions'; import * as cdk from '../../core'; import * as lambda from '../lib'; +const THE_RUNTIME = new lambda.Runtime('node99.x', lambda.RuntimeFamily.NODEJS, { + supportsInlineCode: true, +}); + describe('lambda version', () => { test('can import a Lambda version by ARN', () => { // GIVEN @@ -31,7 +35,7 @@ describe('lambda version', () => { // GIVEN const stack = new cdk.Stack(); const fn = new lambda.Function(stack, 'Fn', { - runtime: lambda.Runtime.NODEJS_LATEST, + runtime: THE_RUNTIME, handler: 'index.handler', code: lambda.Code.fromInline('foo'), }); @@ -63,7 +67,7 @@ describe('lambda version', () => { // GIVEN const stack = new cdk.Stack(); const fn = new lambda.Function(stack, 'Fn', { - runtime: lambda.Runtime.NODEJS_LATEST, + runtime: THE_RUNTIME, handler: 'index.handler', code: lambda.Code.fromInline('foo'), }); @@ -108,7 +112,7 @@ describe('lambda version', () => { // GIVEN const stack = new cdk.Stack(); const fn = new lambda.Function(stack, 'Fn', { - runtime: lambda.Runtime.NODEJS_LATEST, + runtime: THE_RUNTIME, handler: 'index.handler', code: lambda.Code.fromInline('foo'), }); @@ -124,7 +128,7 @@ describe('lambda version', () => { }, FunctionVersion: { 'Fn::GetAtt': [ - 'FnCurrentVersion17A89ABB47320fcc0a7cb943f487b263083e2bb3', + 'FnCurrentVersion17A89ABB30f50e285b0533137b4b353595c6ba57', 'Version', ], }, @@ -136,14 +140,14 @@ describe('lambda version', () => { // GIVEN const stack = new cdk.Stack(); const fn = new lambda.Function(stack, 'Fn', { - runtime: lambda.Runtime.NODEJS_LATEST, + runtime: THE_RUNTIME, handler: 'index.handler', code: lambda.Code.fromInline('foo'), }); const version = fn.currentVersion; // THEN - expect(stack.resolve(version.edgeArn)).toEqual({ Ref: 'FnCurrentVersion17A89ABB47320fcc0a7cb943f487b263083e2bb3' }); + expect(stack.resolve(version.edgeArn)).toEqual({ Ref: 'FnCurrentVersion17A89ABB30f50e285b0533137b4b353595c6ba57' }); }); test('edgeArn throws with $LATEST', () => { @@ -160,7 +164,7 @@ describe('lambda version', () => { const app = new cdk.App(); const stack = new cdk.Stack(app, 'Stack'); const fn = new lambda.Function(stack, 'Fn', { - runtime: lambda.Runtime.NODEJS_LATEST, + runtime: THE_RUNTIME, handler: 'index.handler', code: lambda.Code.fromInline('foo'), }); @@ -168,7 +172,7 @@ describe('lambda version', () => { // WHEN new lambda.Function(stack, 'OtherFn', { - runtime: lambda.Runtime.NODEJS_LATEST, + runtime: THE_RUNTIME, handler: 'index.handler', code: lambda.Code.fromInline('foo'), environment: { @@ -189,7 +193,7 @@ describe('lambda version', () => { const fn = new lambda.Function(stack, 'MyLambda', { code: new lambda.InlineCode('hello()'), handler: 'index.hello', - runtime: lambda.Runtime.NODEJS_LATEST, + runtime: THE_RUNTIME, }); const version = new lambda.Version(stack, 'Version', { lambda: fn, diff --git a/packages/aws-cdk-lib/aws-logs-destinations/test/lambda.test.ts b/packages/aws-cdk-lib/aws-logs-destinations/test/lambda.test.ts index e69de29bb2d1d..f0a63e23e7431 100644 --- a/packages/aws-cdk-lib/aws-logs-destinations/test/lambda.test.ts +++ b/packages/aws-cdk-lib/aws-logs-destinations/test/lambda.test.ts @@ -0,0 +1,106 @@ +import { Template } from '../../assertions'; +import * as lambda from '../../aws-lambda'; +import * as logs from '../../aws-logs'; +import * as cdk from '../../core'; +import * as dests from '../lib'; + +let stack: cdk.Stack; +let fn: lambda.Function; +let logGroup: logs.LogGroup; + +beforeEach(() => { + // GIVEN + stack = new cdk.Stack(); + fn = new lambda.Function(stack, 'MyLambda', { + code: new lambda.InlineCode('foo'), + handler: 'index.handler', + runtime: lambda.Runtime.NODEJS_LATEST, + }); + logGroup = new logs.LogGroup(stack, 'LogGroup'); +}); + +test('lambda can be used as metric subscription destination', () => { + // WHEN + new logs.SubscriptionFilter(stack, 'Subscription', { + logGroup, + destination: new dests.LambdaDestination(fn), + filterPattern: logs.FilterPattern.allEvents(), + }); + + // THEN: subscription target is Lambda + Template.fromStack(stack).hasResourceProperties('AWS::Logs::SubscriptionFilter', { + DestinationArn: { 'Fn::GetAtt': ['MyLambdaCCE802FB', 'Arn'] }, + }); + + // THEN: Lambda has permissions to be invoked by CWL + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Permission', { + Action: 'lambda:InvokeFunction', + FunctionName: { 'Fn::GetAtt': ['MyLambdaCCE802FB', 'Arn'] }, + Principal: 'logs.amazonaws.com', + }); +}); + +test('can have multiple subscriptions use the same Lambda', () => { + // WHEN + new logs.SubscriptionFilter(stack, 'Subscription', { + logGroup, + destination: new dests.LambdaDestination(fn), + filterPattern: logs.FilterPattern.allEvents(), + }); + + new logs.SubscriptionFilter(stack, 'Subscription2', { + logGroup: new logs.LogGroup(stack, 'LG2'), + destination: new dests.LambdaDestination(fn), + filterPattern: logs.FilterPattern.allEvents(), + }); + + // THEN: Lambda has permissions to be invoked by CWL from both Source Arns + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Permission', { + Action: 'lambda:InvokeFunction', + FunctionName: { 'Fn::GetAtt': ['MyLambdaCCE802FB', 'Arn'] }, + SourceArn: { 'Fn::GetAtt': ['LogGroupF5B46931', 'Arn'] }, + Principal: 'logs.amazonaws.com', + }); + + Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Permission', { + Action: 'lambda:InvokeFunction', + FunctionName: { 'Fn::GetAtt': ['MyLambdaCCE802FB', 'Arn'] }, + SourceArn: { 'Fn::GetAtt': ['LG224A94C8F', 'Arn'] }, + Principal: 'logs.amazonaws.com', + }); +}); + +test('lambda permissions are not added when addPermissions is false', () => { + // WHEN + new logs.SubscriptionFilter(stack, 'Subscription', { + logGroup, + destination: new dests.LambdaDestination(fn, { addPermissions: false }), + filterPattern: logs.FilterPattern.allEvents(), + }); + + // THEN: subscription target is Lambda + Template.fromStack(stack).hasResourceProperties('AWS::Logs::SubscriptionFilter', { + DestinationArn: { 'Fn::GetAtt': ['MyLambdaCCE802FB', 'Arn'] }, + }); + + // THEN: Lambda does not have permissions to be invoked by CWL + expect(Template.fromStack(stack).findResources('AWS::Lambda::Permission', { + Action: 'lambda:InvokeFunction', + FunctionName: { 'Fn::GetAtt': ['MyLambdaCCE802FB', 'Arn'] }, + Principal: 'logs.amazonaws.com', + })).toEqual({}); +}); + +test('subscription depends on lambda\'s permission', () => { + // WHEN + new logs.SubscriptionFilter(stack, 'Subscription', { + logGroup, + destination: new dests.LambdaDestination(fn), + filterPattern: logs.FilterPattern.allEvents(), + }); + + // THEN: Subscription filter depends on Lambda's Permission + Template.fromStack(stack).hasResource('AWS::Logs::SubscriptionFilter', { + DependsOn: ['SubscriptionCanInvokeLambdaD31DEAD2'], + }); +}); diff --git a/packages/aws-cdk-lib/custom-resources/test/provider-framework/waiter-state-machine.test.ts b/packages/aws-cdk-lib/custom-resources/test/provider-framework/waiter-state-machine.test.ts index 9181c8b54dae7..8ccdab848460c 100644 --- a/packages/aws-cdk-lib/custom-resources/test/provider-framework/waiter-state-machine.test.ts +++ b/packages/aws-cdk-lib/custom-resources/test/provider-framework/waiter-state-machine.test.ts @@ -1,6 +1,7 @@ import { Node } from 'constructs'; import { Template } from '../../../assertions'; -import { Code, Function as lambdaFn, Runtime } from '../../../aws-lambda'; +import * as lambda from '../../../aws-lambda'; +import { Code, Function as lambdaFn } from '../../../aws-lambda'; import { Duration, Stack } from '../../../core'; import { WaiterStateMachine } from '../../lib/provider-framework/waiter-state-machine'; diff --git a/packages/aws-cdk-lib/triggers/test/triggers.test.ts b/packages/aws-cdk-lib/triggers/test/triggers.test.ts index bd012f1ae0484..f85f0b4b6e3c1 100644 --- a/packages/aws-cdk-lib/triggers/test/triggers.test.ts +++ b/packages/aws-cdk-lib/triggers/test/triggers.test.ts @@ -4,6 +4,10 @@ import * as sns from '../../aws-sns'; import { Duration, Stack } from '../../core'; import * as triggers from '../lib'; +const THE_RUNTIME = new lambda.Runtime('node99.x', lambda.RuntimeFamily.NODEJS, { + supportsInlineCode: true, +}); + test('minimal trigger function', () => { // GIVEN const stack = new Stack(); @@ -11,7 +15,7 @@ test('minimal trigger function', () => { // WHEN new triggers.TriggerFunction(stack, 'MyTrigger', { handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_LATEST, + runtime: THE_RUNTIME, code: lambda.Code.fromInline('foo'), }); @@ -19,7 +23,7 @@ test('minimal trigger function', () => { const template = Template.fromStack(stack); template.hasResourceProperties('AWS::Lambda::Function', {}); template.hasResourceProperties('Custom::Trigger', { - HandlerArn: { Ref: 'MyTriggerCurrentVersion8802742B9328233c8b1874b980ce987912273063' }, + HandlerArn: { Ref: 'MyTriggerCurrentVersion8802742B72295cabb31be670d73807d916cd8e38' }, }); }); @@ -33,7 +37,7 @@ test('before/after', () => { // WHEN const myTrigger = new triggers.TriggerFunction(stack, 'MyTrigger', { - runtime: lambda.Runtime.NODEJS_LATEST, + runtime: THE_RUNTIME, code: lambda.Code.fromInline('zoo'), handler: 'index.handler', @@ -73,13 +77,13 @@ test('multiple functions', () => { // WHEN new triggers.TriggerFunction(stack, 'MyTrigger', { handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_LATEST, + runtime: THE_RUNTIME, code: lambda.Code.fromInline('foo'), }); new triggers.TriggerFunction(stack, 'MySecondTrigger', { handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_LATEST, + runtime: THE_RUNTIME, code: lambda.Code.fromInline('bar'), }); @@ -95,7 +99,7 @@ test('minimal trigger', () => { const stack = new Stack(); const func = new lambda.Function(stack, 'MyFunction', { handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_LATEST, + runtime: THE_RUNTIME, code: lambda.Code.fromInline('foo'), }); @@ -108,7 +112,7 @@ test('minimal trigger', () => { const template = Template.fromStack(stack); template.hasResourceProperties('AWS::Lambda::Function', {}); template.hasResourceProperties('Custom::Trigger', { - HandlerArn: { Ref: 'MyFunctionCurrentVersion197490AF55e50858f6b564bc4745996ce85ee3a6' }, + HandlerArn: { Ref: 'MyFunctionCurrentVersion197490AF59d1c466d521624079e3bb96ed594215' }, ExecuteOnHandlerChange: true, }); }); @@ -118,7 +122,7 @@ test('trigger with optional properties', () => { const stack = new Stack(); const func = new lambda.Function(stack, 'MyFunction', { handler: 'index.handler', - runtime: lambda.Runtime.NODEJS_LATEST, + runtime: THE_RUNTIME, code: lambda.Code.fromInline('foo'), }); @@ -134,7 +138,7 @@ test('trigger with optional properties', () => { const template = Template.fromStack(stack); template.hasResourceProperties('AWS::Lambda::Function', {}); template.hasResourceProperties('Custom::Trigger', { - HandlerArn: { Ref: 'MyFunctionCurrentVersion197490AF55e50858f6b564bc4745996ce85ee3a6' }, + HandlerArn: { Ref: 'MyFunctionCurrentVersion197490AF59d1c466d521624079e3bb96ed594215' }, Timeout: '600000', InvocationType: 'Event', ExecuteOnHandlerChange: false, From 09f249bbbe006b78f32ee2f4bb74de26825c89d2 Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Wed, 6 Sep 2023 11:25:19 +0200 Subject: [PATCH 4/6] Fix some imports --- .../aws-apigatewayv2-authorizers-alpha/test/http/lambda.test.ts | 1 - .../test/websocket/iam.test.ts | 1 - .../test/websocket/lambda.test.ts | 1 - .../aws-apigatewayv2-integrations-alpha/test/http/lambda.test.ts | 1 - .../test/websocket/lambda.test.ts | 1 - .../test/lambda/lambda-function-action.test.ts | 1 - .../test/s3-bucket.test.ts | 1 - packages/@aws-cdk/aws-lambda-python-alpha/test/function.test.ts | 1 - .../aws-s3objectlambda-alpha/test/s3objectlambda.test.ts | 1 - 9 files changed, 9 deletions(-) diff --git a/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/http/lambda.test.ts b/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/http/lambda.test.ts index b80f48c12b680..45a19729f7b1d 100644 --- a/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/http/lambda.test.ts +++ b/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/http/lambda.test.ts @@ -1,7 +1,6 @@ import { Match, Template } from 'aws-cdk-lib/assertions'; import { HttpApi } from '@aws-cdk/aws-apigatewayv2-alpha'; import { Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda'; -import { lambda.Runtime.NODEJS_LATEST } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; import { Duration, Stack } from 'aws-cdk-lib'; import { DummyRouteIntegration } from './integration'; import { HttpLambdaAuthorizer, HttpLambdaResponseType } from '../../lib'; diff --git a/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/websocket/iam.test.ts b/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/websocket/iam.test.ts index b30a830ff5480..aef94e4c639fd 100644 --- a/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/websocket/iam.test.ts +++ b/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/websocket/iam.test.ts @@ -2,7 +2,6 @@ import { Template } from 'aws-cdk-lib/assertions'; import { WebSocketApi } from '@aws-cdk/aws-apigatewayv2-alpha'; import { WebSocketLambdaIntegration } from '@aws-cdk/aws-apigatewayv2-integrations-alpha'; import { Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda'; -import { lambda.Runtime.NODEJS_LATEST } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; import { Stack } from 'aws-cdk-lib'; import { WebSocketIamAuthorizer } from '../../lib'; diff --git a/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/websocket/lambda.test.ts b/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/websocket/lambda.test.ts index df5178ddaff4c..06b6ba5de8a0d 100644 --- a/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/websocket/lambda.test.ts +++ b/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/websocket/lambda.test.ts @@ -2,7 +2,6 @@ import { Template } from 'aws-cdk-lib/assertions'; import { WebSocketApi } from '@aws-cdk/aws-apigatewayv2-alpha'; import { WebSocketLambdaIntegration } from '@aws-cdk/aws-apigatewayv2-integrations-alpha'; import { Code, Function } from 'aws-cdk-lib/aws-lambda'; -import { lambda.Runtime.NODEJS_LATEST } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; import { Stack } from 'aws-cdk-lib'; import { WebSocketLambdaAuthorizer } from '../../lib'; diff --git a/packages/@aws-cdk/aws-apigatewayv2-integrations-alpha/test/http/lambda.test.ts b/packages/@aws-cdk/aws-apigatewayv2-integrations-alpha/test/http/lambda.test.ts index f615746ada9be..b93f78d17c0c1 100644 --- a/packages/@aws-cdk/aws-apigatewayv2-integrations-alpha/test/http/lambda.test.ts +++ b/packages/@aws-cdk/aws-apigatewayv2-integrations-alpha/test/http/lambda.test.ts @@ -1,7 +1,6 @@ import { Match, Template } from 'aws-cdk-lib/assertions'; import { HttpApi, HttpRoute, HttpRouteKey, MappingValue, ParameterMapping, PayloadFormatVersion } from '@aws-cdk/aws-apigatewayv2-alpha'; import { Code, Function } from 'aws-cdk-lib/aws-lambda'; -import { lambda.Runtime.NODEJS_LATEST } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; import { App, Stack } from 'aws-cdk-lib'; import { HttpLambdaIntegration } from '../../lib'; diff --git a/packages/@aws-cdk/aws-apigatewayv2-integrations-alpha/test/websocket/lambda.test.ts b/packages/@aws-cdk/aws-apigatewayv2-integrations-alpha/test/websocket/lambda.test.ts index 9ad9f16222891..c459a919827f3 100644 --- a/packages/@aws-cdk/aws-apigatewayv2-integrations-alpha/test/websocket/lambda.test.ts +++ b/packages/@aws-cdk/aws-apigatewayv2-integrations-alpha/test/websocket/lambda.test.ts @@ -1,7 +1,6 @@ import { Template } from 'aws-cdk-lib/assertions'; import { WebSocketApi } from '@aws-cdk/aws-apigatewayv2-alpha'; import { Code, Function } from 'aws-cdk-lib/aws-lambda'; -import { lambda.Runtime.NODEJS_LATEST } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; import { Stack } from 'aws-cdk-lib'; import { WebSocketLambdaIntegration } from '../../lib'; diff --git a/packages/@aws-cdk/aws-iot-actions-alpha/test/lambda/lambda-function-action.test.ts b/packages/@aws-cdk/aws-iot-actions-alpha/test/lambda/lambda-function-action.test.ts index 8c8d1555af806..43b0aef40a0bd 100644 --- a/packages/@aws-cdk/aws-iot-actions-alpha/test/lambda/lambda-function-action.test.ts +++ b/packages/@aws-cdk/aws-iot-actions-alpha/test/lambda/lambda-function-action.test.ts @@ -3,7 +3,6 @@ import * as iot from '@aws-cdk/aws-iot-alpha'; import * as lambda from 'aws-cdk-lib/aws-lambda'; import * as cdk from 'aws-cdk-lib'; import * as actions from '../../lib'; -import { lambda.Runtime.NODEJS_LATEST } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; test('create a topic rule with lambda action and a lambda permission to be invoked by the topic rule', () => { // GIVEN diff --git a/packages/@aws-cdk/aws-kinesisfirehose-destinations-alpha/test/s3-bucket.test.ts b/packages/@aws-cdk/aws-kinesisfirehose-destinations-alpha/test/s3-bucket.test.ts index a2f9be9829be1..18404c284ce2b 100644 --- a/packages/@aws-cdk/aws-kinesisfirehose-destinations-alpha/test/s3-bucket.test.ts +++ b/packages/@aws-cdk/aws-kinesisfirehose-destinations-alpha/test/s3-bucket.test.ts @@ -3,7 +3,6 @@ import * as iam from 'aws-cdk-lib/aws-iam'; import * as firehose from '@aws-cdk/aws-kinesisfirehose-alpha'; import * as kms from 'aws-cdk-lib/aws-kms'; import * as lambda from 'aws-cdk-lib/aws-lambda'; -import { lambda.Runtime.NODEJS_LATEST } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; import * as logs from 'aws-cdk-lib/aws-logs'; import * as s3 from 'aws-cdk-lib/aws-s3'; import * as cdk from 'aws-cdk-lib'; diff --git a/packages/@aws-cdk/aws-lambda-python-alpha/test/function.test.ts b/packages/@aws-cdk/aws-lambda-python-alpha/test/function.test.ts index 70dd4ab23b178..30cc0fec6ae61 100644 --- a/packages/@aws-cdk/aws-lambda-python-alpha/test/function.test.ts +++ b/packages/@aws-cdk/aws-lambda-python-alpha/test/function.test.ts @@ -1,7 +1,6 @@ import * as path from 'path'; import { Template } from 'aws-cdk-lib/assertions'; import { Code, Runtime } from 'aws-cdk-lib/aws-lambda'; -import { lambda.Runtime.NODEJS_LATEST } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; import { AssetHashType, DockerImage, Stack } from 'aws-cdk-lib'; import { PythonFunction } from '../lib'; import { Bundling, BundlingProps } from '../lib/bundling'; diff --git a/packages/@aws-cdk/aws-s3objectlambda-alpha/test/s3objectlambda.test.ts b/packages/@aws-cdk/aws-s3objectlambda-alpha/test/s3objectlambda.test.ts index 5ec3514e080c1..0f00a8be8fa91 100644 --- a/packages/@aws-cdk/aws-s3objectlambda-alpha/test/s3objectlambda.test.ts +++ b/packages/@aws-cdk/aws-s3objectlambda-alpha/test/s3objectlambda.test.ts @@ -1,6 +1,5 @@ import { Template } from 'aws-cdk-lib/assertions'; import * as lambda from 'aws-cdk-lib/aws-lambda'; -import { lambda.Runtime.NODEJS_LATEST } from 'aws-cdk-lib/aws-lambda/lib/helpers-internal'; import * as s3 from 'aws-cdk-lib/aws-s3'; import * as cdk from 'aws-cdk-lib'; import { AccessPoint } from '../lib'; From ba659abca1021373ad13fd0c8a8526a3b504f9bb Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Wed, 6 Sep 2023 12:30:02 +0200 Subject: [PATCH 5/6] Two small import fixes --- .../aws-apigatewayv2-integrations-alpha/test/http/lambda.test.ts | 1 + packages/@aws-cdk/aws-lambda-python-alpha/test/function.test.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/@aws-cdk/aws-apigatewayv2-integrations-alpha/test/http/lambda.test.ts b/packages/@aws-cdk/aws-apigatewayv2-integrations-alpha/test/http/lambda.test.ts index b93f78d17c0c1..38336d8ada2e7 100644 --- a/packages/@aws-cdk/aws-apigatewayv2-integrations-alpha/test/http/lambda.test.ts +++ b/packages/@aws-cdk/aws-apigatewayv2-integrations-alpha/test/http/lambda.test.ts @@ -1,6 +1,7 @@ import { Match, Template } from 'aws-cdk-lib/assertions'; import { HttpApi, HttpRoute, HttpRouteKey, MappingValue, ParameterMapping, PayloadFormatVersion } from '@aws-cdk/aws-apigatewayv2-alpha'; import { Code, Function } from 'aws-cdk-lib/aws-lambda'; +import * as lambda from 'aws-cdk-lib/aws-lambda'; import { App, Stack } from 'aws-cdk-lib'; import { HttpLambdaIntegration } from '../../lib'; diff --git a/packages/@aws-cdk/aws-lambda-python-alpha/test/function.test.ts b/packages/@aws-cdk/aws-lambda-python-alpha/test/function.test.ts index 30cc0fec6ae61..a8bf7ffaceafb 100644 --- a/packages/@aws-cdk/aws-lambda-python-alpha/test/function.test.ts +++ b/packages/@aws-cdk/aws-lambda-python-alpha/test/function.test.ts @@ -1,6 +1,7 @@ import * as path from 'path'; import { Template } from 'aws-cdk-lib/assertions'; import { Code, Runtime } from 'aws-cdk-lib/aws-lambda'; +import * as lambda from 'aws-cdk-lib/aws-lambda'; import { AssetHashType, DockerImage, Stack } from 'aws-cdk-lib'; import { PythonFunction } from '../lib'; import { Bundling, BundlingProps } from '../lib/bundling'; From 74fd6852910bff0fdceaf51eedc25e29a26b6756 Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Wed, 6 Sep 2023 13:12:14 +0200 Subject: [PATCH 6/6] More imports --- .../test/http/lambda.test.ts | 3 ++- .../test/websocket/iam.test.ts | 3 ++- .../test/websocket/lambda.test.ts | 1 + .../test/websocket/lambda.test.ts | 1 + 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/http/lambda.test.ts b/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/http/lambda.test.ts index 45a19729f7b1d..bc02f4f30781b 100644 --- a/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/http/lambda.test.ts +++ b/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/http/lambda.test.ts @@ -1,6 +1,7 @@ import { Match, Template } from 'aws-cdk-lib/assertions'; import { HttpApi } from '@aws-cdk/aws-apigatewayv2-alpha'; -import { Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda'; +import { Code, Function } from 'aws-cdk-lib/aws-lambda'; +import * as lambda from 'aws-cdk-lib/aws-lambda'; import { Duration, Stack } from 'aws-cdk-lib'; import { DummyRouteIntegration } from './integration'; import { HttpLambdaAuthorizer, HttpLambdaResponseType } from '../../lib'; diff --git a/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/websocket/iam.test.ts b/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/websocket/iam.test.ts index aef94e4c639fd..ed58870bf5961 100644 --- a/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/websocket/iam.test.ts +++ b/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/websocket/iam.test.ts @@ -1,7 +1,8 @@ import { Template } from 'aws-cdk-lib/assertions'; import { WebSocketApi } from '@aws-cdk/aws-apigatewayv2-alpha'; import { WebSocketLambdaIntegration } from '@aws-cdk/aws-apigatewayv2-integrations-alpha'; -import { Code, Function, Runtime } from 'aws-cdk-lib/aws-lambda'; +import { Code, Function } from 'aws-cdk-lib/aws-lambda'; +import * as lambda from 'aws-cdk-lib/aws-lambda'; import { Stack } from 'aws-cdk-lib'; import { WebSocketIamAuthorizer } from '../../lib'; diff --git a/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/websocket/lambda.test.ts b/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/websocket/lambda.test.ts index 06b6ba5de8a0d..8a8993f190188 100644 --- a/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/websocket/lambda.test.ts +++ b/packages/@aws-cdk/aws-apigatewayv2-authorizers-alpha/test/websocket/lambda.test.ts @@ -2,6 +2,7 @@ import { Template } from 'aws-cdk-lib/assertions'; import { WebSocketApi } from '@aws-cdk/aws-apigatewayv2-alpha'; import { WebSocketLambdaIntegration } from '@aws-cdk/aws-apigatewayv2-integrations-alpha'; import { Code, Function } from 'aws-cdk-lib/aws-lambda'; +import * as lambda from 'aws-cdk-lib/aws-lambda'; import { Stack } from 'aws-cdk-lib'; import { WebSocketLambdaAuthorizer } from '../../lib'; diff --git a/packages/@aws-cdk/aws-apigatewayv2-integrations-alpha/test/websocket/lambda.test.ts b/packages/@aws-cdk/aws-apigatewayv2-integrations-alpha/test/websocket/lambda.test.ts index c459a919827f3..1a915ffbf9c4f 100644 --- a/packages/@aws-cdk/aws-apigatewayv2-integrations-alpha/test/websocket/lambda.test.ts +++ b/packages/@aws-cdk/aws-apigatewayv2-integrations-alpha/test/websocket/lambda.test.ts @@ -1,6 +1,7 @@ import { Template } from 'aws-cdk-lib/assertions'; import { WebSocketApi } from '@aws-cdk/aws-apigatewayv2-alpha'; import { Code, Function } from 'aws-cdk-lib/aws-lambda'; +import * as lambda from 'aws-cdk-lib/aws-lambda'; import { Stack } from 'aws-cdk-lib'; import { WebSocketLambdaIntegration } from '../../lib';