From e8af3914188c23b9744ad1e373165ff738ce023a Mon Sep 17 00:00:00 2001 From: Mitchell Valine Date: Wed, 2 Aug 2023 11:08:19 -0700 Subject: [PATCH 1/3] chore: remove DEFAULT_CR_NODE_VERSION regional map Removes the map of regions -> available lambda nodejs runtime versions that previously was used for all custom resources vended in the aws-cdk. --- .../custom-resource-provider.ts | 10 --------- .../custom-resource-provider.test.ts | 19 +--------------- .../aws-cdk-lib/custom-resources/README.md | 15 +------------ .../aws-custom-resource.ts | 14 ------------ .../aws-custom-resource.test.ts | 22 +------------------ .../region-info/build-tools/fact-tables.ts | 8 ------- .../build-tools/generate-static-data.ts | 3 --- packages/aws-cdk-lib/region-info/lib/fact.ts | 5 ----- 8 files changed, 3 insertions(+), 93 deletions(-) diff --git a/packages/aws-cdk-lib/core/lib/custom-resource-provider/custom-resource-provider.ts b/packages/aws-cdk-lib/core/lib/custom-resource-provider/custom-resource-provider.ts index 5901724caae22..8825f49ab38be 100644 --- a/packages/aws-cdk-lib/core/lib/custom-resource-provider/custom-resource-provider.ts +++ b/packages/aws-cdk-lib/core/lib/custom-resource-provider/custom-resource-provider.ts @@ -2,7 +2,6 @@ import * as path from 'path'; import { Construct } from 'constructs'; import * as fs from 'fs-extra'; import * as cxapi from '../../../cx-api'; -import { FactName } from '../../../region-info'; import { AssetStaging } from '../asset-staging'; import { FileAssetPackaging } from '../assets'; import { CfnResource } from '../cfn-resource'; @@ -18,15 +17,6 @@ const ENTRYPOINT_FILENAME = '__entrypoint__'; const ENTRYPOINT_NODEJS_SOURCE = path.join(__dirname, 'nodejs-entrypoint.js'); export const INLINE_CUSTOM_RESOURCE_CONTEXT = '@aws-cdk/core:inlineCustomResourceIfPossible'; -/** - * The lambda runtime used by default for aws-cdk vended custom resources. Can change - * based on region. - */ -export function builtInCustomResourceProviderNodeRuntime(scope: Construct): CustomResourceProviderRuntime { - const runtimeName = Stack.of(scope).regionalFact(FactName.DEFAULT_CR_NODE_VERSION, 'nodejs16.x'); - return Object.values(CustomResourceProviderRuntime).find(value => value === runtimeName) ?? CustomResourceProviderRuntime.NODEJS_16_X; -} - /** * Initialization properties for `CustomResourceProvider`. * 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 81a6ad56b8594..803404a776154 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 @@ -1,7 +1,7 @@ import * as fs from 'fs'; import * as path from 'path'; import * as cxapi from '../../../cx-api'; -import { builtInCustomResourceProviderNodeRuntime, App, AssetStaging, CustomResourceProvider, CustomResourceProviderRuntime, DockerImageAssetLocation, DockerImageAssetSource, Duration, FileAssetLocation, FileAssetSource, ISynthesisSession, Size, Stack, CfnResource } from '../../lib'; +import { App, AssetStaging, CustomResourceProvider, CustomResourceProviderRuntime, DockerImageAssetLocation, DockerImageAssetSource, Duration, FileAssetLocation, FileAssetSource, ISynthesisSession, Size, Stack, CfnResource } from '../../lib'; import { CUSTOMIZE_ROLES_CONTEXT_KEY } from '../../lib/helpers-internal'; import { toCloudFormation } from '../util'; @@ -457,22 +457,5 @@ describe('custom resource provider', () => { }); }); - describe('builtInCustomResourceProviderNodeRuntime', () => { - test('returns node16 for commercial region', () => { - const app = new App(); - const stack = new Stack(app, 'MyStack', { env: { region: 'us-east-1' } }); - - const rt = builtInCustomResourceProviderNodeRuntime(stack); - expect(rt).toEqual(CustomResourceProviderRuntime.NODEJS_16_X); - }); - - test('returns node14 for iso region', () => { - const app = new App(); - const stack = new Stack(app, 'MyStack', { env: { region: 'us-iso-east-1' } }); - - const rt = builtInCustomResourceProviderNodeRuntime(stack); - expect(rt).toEqual(CustomResourceProviderRuntime.NODEJS_14_X); - }); - }); }); diff --git a/packages/aws-cdk-lib/custom-resources/README.md b/packages/aws-cdk-lib/custom-resources/README.md index ff26dce218187..302fcefbca8a3 100644 --- a/packages/aws-cdk-lib/custom-resources/README.md +++ b/packages/aws-cdk-lib/custom-resources/README.md @@ -651,20 +651,9 @@ const getParameter = new cr.AwsCustomResource(this, 'AssociateVPCWithHostedZone' #### Using AWS SDK for JavaScript v3 -`AwsCustomResource` experimentally supports AWS SDK for JavaScript v3 (NODEJS_18_X or higher). In AWS SDK for JavaScript v3, packages are installed for each service. Therefore, specify the package name for `service`. Also, `action` specifies the XxxClient operations provided in the package. This example is the same as `SSM.getParameter` in v2. +`AwsCustomResource` uses Node 18 and aws sdk v3 by default. You can specify the service as either the name of the sdk module, or just the service name, IE `@aws-sdk/client-ssm` or `SSM`, and the action as either the client method name or the sdk v3 command, `getParameter` or `GetParameterCommand`. It is recommended to use the v3 format for new AwsCustomResources going forward. ```ts -import * as regionInfo from 'aws-cdk-lib/region-info'; - -class MyFact implements regionInfo.IFact { - public readonly region = 'us-east-1'; - public readonly name = regionInfo.FactName.DEFAULT_CR_NODE_VERSION; - public readonly value = lambda.Runtime.NODEJS_18_X.name; -} - -// change custom resource default runtime -regionInfo.Fact.register(new MyFact(), true); - new cr.AwsCustomResource(this, 'GetParameter', { resourceType: 'Custom::SSMParameter', onUpdate: { @@ -678,5 +667,3 @@ new cr.AwsCustomResource(this, 'GetParameter', { }, }); ``` - -If you are using `NODEJS_18_X` or higher, you can also use the existing AWS SDK for JavaScript v2 style. diff --git a/packages/aws-cdk-lib/custom-resources/lib/aws-custom-resource/aws-custom-resource.ts b/packages/aws-cdk-lib/custom-resources/lib/aws-custom-resource/aws-custom-resource.ts index 31a9045961742..ebef978b8cf46 100644 --- a/packages/aws-cdk-lib/custom-resources/lib/aws-custom-resource/aws-custom-resource.ts +++ b/packages/aws-cdk-lib/custom-resources/lib/aws-custom-resource/aws-custom-resource.ts @@ -9,20 +9,6 @@ import * as logs from '../../../aws-logs'; import * as cdk from '../../../core'; import { Annotations } from '../../../core'; import * as cxapi from '../../../cx-api'; -import { FactName } from '../../../region-info'; - -/** - * The lambda runtime used by default for aws-cdk vended custom resources. Can change - * based on region. - */ -export function builtInCustomResourceNodeRuntime(scope: Construct): lambda.Runtime { - // Runtime regional fact should always return a known runtime string that lambda.Runtime - // can index off, but for type safety we also default it here. - const runtimeName = cdk.Stack.of(scope).regionalFact(FactName.DEFAULT_CR_NODE_VERSION, 'nodejs16.x'); - return runtimeName - ? new lambda.Runtime(runtimeName, lambda.RuntimeFamily.NODEJS, { supportsInlineCode: true }) - : lambda.Runtime.NODEJS_16_X; -} /** * Reference to the physical resource id that can be passed to the AWS operation as a parameter. diff --git a/packages/aws-cdk-lib/custom-resources/test/aws-custom-resource/aws-custom-resource.test.ts b/packages/aws-cdk-lib/custom-resources/test/aws-custom-resource/aws-custom-resource.test.ts index 50e015deddec5..d81086f182b29 100644 --- a/packages/aws-cdk-lib/custom-resources/test/aws-custom-resource/aws-custom-resource.test.ts +++ b/packages/aws-cdk-lib/custom-resources/test/aws-custom-resource/aws-custom-resource.test.ts @@ -1,11 +1,10 @@ import { Template } from '../../../assertions'; import * as ec2 from '../../../aws-ec2'; import * as iam from '../../../aws-iam'; -import * as lambda from '../../../aws-lambda'; import * as logs from '../../../aws-logs'; import * as cdk from '../../../core'; import { App, Stack } from '../../../core'; -import { AwsCustomResource, AwsCustomResourcePolicy, PhysicalResourceId, PhysicalResourceIdReference, builtInCustomResourceNodeRuntime } from '../../lib'; +import { AwsCustomResource, AwsCustomResourcePolicy, PhysicalResourceId, PhysicalResourceIdReference } from '../../lib'; /* eslint-disable quote-props */ @@ -1280,22 +1279,3 @@ test('can specify removal policy', () => { DeletionPolicy: 'Retain', }); }); - -describe('builtInCustomResourceNodeRuntime', () => { - test('returns node16 for commercial region', () => { - const app = new App(); - const stack = new Stack(app, 'MyStack', { env: { region: 'us-east-1' } }); - - const rt = builtInCustomResourceNodeRuntime(stack); - expect(rt).toEqual(lambda.Runtime.NODEJS_16_X); - }); - - test('returns node14 for iso region', () => { - const app = new App(); - const stack = new Stack(app, 'MyStack', { env: { region: 'us-iso-east-1' } }); - - const rt = builtInCustomResourceNodeRuntime(stack); - expect(rt).toEqual(lambda.Runtime.NODEJS_14_X); - }); -}); - diff --git a/packages/aws-cdk-lib/region-info/build-tools/fact-tables.ts b/packages/aws-cdk-lib/region-info/build-tools/fact-tables.ts index 834329ba8bf61..87eadc59c68aa 100644 --- a/packages/aws-cdk-lib/region-info/build-tools/fact-tables.ts +++ b/packages/aws-cdk-lib/region-info/build-tools/fact-tables.ts @@ -122,14 +122,6 @@ export const PARTITION_MAP: { [region: string]: Region } = { 'us-isob-': { partition: Partition.UsIsoB, domainSuffix: 'sc2s.sgov.gov' }, }; -export const CR_DEFAULT_RUNTIME_MAP: Record = { - [Partition.Default]: 'nodejs16.x', - [Partition.Cn]: 'nodejs16.x', - [Partition.UsGov]: 'nodejs16.x', - [Partition.UsIso]: 'nodejs14.x', - [Partition.UsIsoB]: 'nodejs14.x', -}; - // https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-access-logs.html#access-logging-bucket-permissions // https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/enable-access-logs.html#attach-bucket-policy // Any not listed regions use the service principal "logdelivery.elasticloadbalancing.amazonaws.com" diff --git a/packages/aws-cdk-lib/region-info/build-tools/generate-static-data.ts b/packages/aws-cdk-lib/region-info/build-tools/generate-static-data.ts index 0313246c43a15..badafeb57b204 100644 --- a/packages/aws-cdk-lib/region-info/build-tools/generate-static-data.ts +++ b/packages/aws-cdk-lib/region-info/build-tools/generate-static-data.ts @@ -11,7 +11,6 @@ import { ROUTE_53_BUCKET_WEBSITE_ZONE_IDS, EBS_ENV_ENDPOINT_HOSTED_ZONE_IDS, ADOT_LAMBDA_LAYER_ARNS, - CR_DEFAULT_RUNTIME_MAP, PARAMS_AND_SECRETS_LAMBDA_LAYER_ARNS, } from './fact-tables'; import { @@ -83,8 +82,6 @@ export async function main(): Promise { registerFact(region, 'APPMESH_ECR_ACCOUNT', APPMESH_ECR_ACCOUNTS[region]); - registerFact(region, 'DEFAULT_CR_NODE_VERSION', CR_DEFAULT_RUNTIME_MAP[partition]); - const firehoseCidrBlock = FIREHOSE_CIDR_BLOCKS[region]; if (firehoseCidrBlock) { registerFact(region, 'FIREHOSE_CIDR_BLOCK', `${FIREHOSE_CIDR_BLOCKS[region]}/27`); diff --git a/packages/aws-cdk-lib/region-info/lib/fact.ts b/packages/aws-cdk-lib/region-info/lib/fact.ts index 7ccc6df1c84b5..728d66d345475 100644 --- a/packages/aws-cdk-lib/region-info/lib/fact.ts +++ b/packages/aws-cdk-lib/region-info/lib/fact.ts @@ -171,11 +171,6 @@ export class FactName { */ public static readonly FIREHOSE_CIDR_BLOCK = 'firehoseCidrBlock'; - /** - * The default NodeJS version used for custom resource function runtimes - */ - public static readonly DEFAULT_CR_NODE_VERSION = 'defaultCrNodeVersion'; - /** * The ARN of CloudWatch Lambda Insights for a version (e.g. 1.0.98.0) */ From f068142d4be2a961140bd19bc97411bb7abc4974 Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Tue, 22 Aug 2023 11:23:52 +0200 Subject: [PATCH 2/3] Allowed breaking change --- allowed-breaking-changes.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/allowed-breaking-changes.txt b/allowed-breaking-changes.txt index 99fbbed4cc359..5398e865712a8 100644 --- a/allowed-breaking-changes.txt +++ b/allowed-breaking-changes.txt @@ -173,3 +173,6 @@ removed:aws-cdk-lib.aws_ecs.CfnTaskSet.LoadBalancerProperty.loadBalancerName # Introduction of a new feature # Previously only BlueGreenUpdatePolicy could be set, now BlueGreenUpdatePolicy or new RollingUpdatePolicy can be provided weakened:aws-cdk-lib.aws_sagemaker.CfnEndpoint.DeploymentConfigProperty + +# Removed for being unused +removed:@aws-cdk/region-info.FactName.DEFAULT_CR_NODE_VERSION From 72309b604bab5a7df9b84e23afffb8f154cf6015 Mon Sep 17 00:00:00 2001 From: Rico Hermans Date: Tue, 22 Aug 2023 15:29:09 +0200 Subject: [PATCH 3/3] Update allowed-breaking-changes.txt --- allowed-breaking-changes.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/allowed-breaking-changes.txt b/allowed-breaking-changes.txt index 54edd6f255d88..2f4d77b2757bd 100644 --- a/allowed-breaking-changes.txt +++ b/allowed-breaking-changes.txt @@ -176,6 +176,7 @@ weakened:aws-cdk-lib.aws_sagemaker.CfnEndpoint.DeploymentConfigProperty # Removed for being unused removed:@aws-cdk/region-info.FactName.DEFAULT_CR_NODE_VERSION +removed:aws-cdk-lib.region_info.FactName.DEFAULT_CR_NODE_VERSION # These should have been marked external weakened:aws-cdk-lib.aws_events.CfnRule.RedshiftDataParametersProperty