Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove DEFAULT_CR_NODE_VERSION regional map #26665

Merged
merged 8 commits into from
Aug 22, 2023
3 changes: 1 addition & 2 deletions packages/aws-cdk-lib/aws-logs/lib/log-retention.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import * as iam from '../../aws-iam';
import * as s3_assets from '../../aws-s3-assets';
import * as cdk from '../../core';
import { ArnFormat } from '../../core';
import { FactName } from '../../region-info';

/**
* Construction properties for a LogRetention.
Expand Down Expand Up @@ -171,7 +170,7 @@ class LogRetentionFunction extends Construct implements cdk.ITaggable {
type: 'AWS::Lambda::Function',
properties: {
Handler: 'index.handler',
Runtime: cdk.Stack.of(scope).regionalFact(FactName.DEFAULT_CR_NODE_VERSION, 'nodejs18.x'), // Equivalent to Runtime.NODEJS_18_X
Runtime: 'nodejs18.x',
Code: {
S3Bucket: asset.s3BucketName,
S3Key: asset.s3ObjectKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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, 'nodejs18.x');
return Object.values(CustomResourceProviderRuntime).find(value => value === runtimeName) ?? CustomResourceProviderRuntime.NODEJS_18_X;
}

/**
* Initialization properties for `CustomResourceProvider`.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -457,22 +457,5 @@ describe('custom resource provider', () => {
});

});
describe('builtInCustomResourceProviderNodeRuntime', () => {
test('returns node18 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_18_X);
});

test('returns node18 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_18_X);
});
});
});

19 changes: 19 additions & 0 deletions packages/aws-cdk-lib/custom-resources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -648,3 +648,22 @@ const getParameter = new cr.AwsCustomResource(this, 'AssociateVPCWithHostedZone'
}),
});
```

#### Using AWS SDK for JavaScript v3

`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
new cr.AwsCustomResource(this, 'GetParameter', {
resourceType: 'Custom::SSMParameter',
onUpdate: {
service: '@aws-sdk/client-ssm', // 'SSM' in v2
action: 'GetParameterCommand', // 'getParameter' in v2
parameters: {
Name: 'foo',
WithDecryption: true,
},
physicalResourceId: cr.PhysicalResourceId.fromResponse('Parameter.ARN'),
},
});
```
Original file line number Diff line number Diff line change
Expand Up @@ -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, 'nodejs18.x');
return runtimeName
? new lambda.Runtime(runtimeName, lambda.RuntimeFamily.NODEJS, { supportsInlineCode: true })
: lambda.Runtime.NODEJS_18_X;
}

/**
* Reference to the physical resource id that can be passed to the AWS operation as a parameter.
Expand Down
Original file line number Diff line number Diff line change
@@ -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 */

Expand Down Expand Up @@ -1280,22 +1279,3 @@ test('can specify removal policy', () => {
DeletionPolicy: 'Retain',
});
});

describe('builtInCustomResourceNodeRuntime', () => {
test('returns node18 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_18_X);
});

test('returns node18 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_18_X);
});
});

8 changes: 0 additions & 8 deletions packages/aws-cdk-lib/region-info/build-tools/fact-tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, string> = {
[Partition.Default]: 'nodejs18.x',
[Partition.Cn]: 'nodejs18.x',
[Partition.UsGov]: 'nodejs18.x',
[Partition.UsIso]: 'nodejs18.x',
[Partition.UsIsoB]: 'nodejs18.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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -83,8 +82,6 @@ export async function main(): Promise<void> {

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`);
Expand Down
5 changes: 0 additions & 5 deletions packages/aws-cdk-lib/region-info/lib/fact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
Expand Down
Loading