From 3947bc44a1f649b11c12e5d344775be3d4080abf Mon Sep 17 00:00:00 2001 From: Adam Ruka Date: Thu, 13 May 2021 00:37:33 -0700 Subject: [PATCH] chore(custom-resources): import the AWSLambda package explicitly (#14643) When linking the aws-cdk repository to a CDK app using the `link-all.sh` script, if the app uses `ts-node`, the Lambda code in the @aws-cdk/custom-resources package gets picked up by the TypeScript compiler. That code relied on the `aws-lambda` package being implicitly available, but that would cause `ts-node` to fail. Add an explicit import of it in the code - I checked the only difference in the generated JS code is the sourceMappingUrl, so it shouldn't make a difference at runtime, but allows `ts-node` to load that file successfully. Fixes #11627 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../aws-msk/test/integ.cluster.expected.json | 18 +++++++++--------- .../lib/aws-custom-resource/runtime/index.ts | 8 +++++++- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/@aws-cdk/aws-msk/test/integ.cluster.expected.json b/packages/@aws-cdk/aws-msk/test/integ.cluster.expected.json index 43769c1b25ac8..769c0533269cd 100644 --- a/packages/@aws-cdk/aws-msk/test/integ.cluster.expected.json +++ b/packages/@aws-cdk/aws-msk/test/integ.cluster.expected.json @@ -524,7 +524,7 @@ "Properties": { "Code": { "S3Bucket": { - "Ref": "AssetParametersb965ea3084ec95e24846d4975623e62a02c21883c3ddea9366b2ae42d21cef98S3Bucket4DD075F7" + "Ref": "AssetParametersf56a9c742f3e99b26237d5d0912c69f9db8289c13656fdcb490fd017d801c483S3Bucket9DEDD0AB" }, "S3Key": { "Fn::Join": [ @@ -537,7 +537,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParametersb965ea3084ec95e24846d4975623e62a02c21883c3ddea9366b2ae42d21cef98S3VersionKeyBD0E03B7" + "Ref": "AssetParametersf56a9c742f3e99b26237d5d0912c69f9db8289c13656fdcb490fd017d801c483S3VersionKeyA54743D3" } ] } @@ -550,7 +550,7 @@ "Fn::Split": [ "||", { - "Ref": "AssetParametersb965ea3084ec95e24846d4975623e62a02c21883c3ddea9366b2ae42d21cef98S3VersionKeyBD0E03B7" + "Ref": "AssetParametersf56a9c742f3e99b26237d5d0912c69f9db8289c13656fdcb490fd017d801c483S3VersionKeyA54743D3" } ] } @@ -576,17 +576,17 @@ } }, "Parameters": { - "AssetParametersb965ea3084ec95e24846d4975623e62a02c21883c3ddea9366b2ae42d21cef98S3Bucket4DD075F7": { + "AssetParametersf56a9c742f3e99b26237d5d0912c69f9db8289c13656fdcb490fd017d801c483S3Bucket9DEDD0AB": { "Type": "String", - "Description": "S3 bucket for asset \"b965ea3084ec95e24846d4975623e62a02c21883c3ddea9366b2ae42d21cef98\"" + "Description": "S3 bucket for asset \"f56a9c742f3e99b26237d5d0912c69f9db8289c13656fdcb490fd017d801c483\"" }, - "AssetParametersb965ea3084ec95e24846d4975623e62a02c21883c3ddea9366b2ae42d21cef98S3VersionKeyBD0E03B7": { + "AssetParametersf56a9c742f3e99b26237d5d0912c69f9db8289c13656fdcb490fd017d801c483S3VersionKeyA54743D3": { "Type": "String", - "Description": "S3 key for asset version \"b965ea3084ec95e24846d4975623e62a02c21883c3ddea9366b2ae42d21cef98\"" + "Description": "S3 key for asset version \"f56a9c742f3e99b26237d5d0912c69f9db8289c13656fdcb490fd017d801c483\"" }, - "AssetParametersb965ea3084ec95e24846d4975623e62a02c21883c3ddea9366b2ae42d21cef98ArtifactHash35A756EB": { + "AssetParametersf56a9c742f3e99b26237d5d0912c69f9db8289c13656fdcb490fd017d801c483ArtifactHash228F5AF4": { "Type": "String", - "Description": "Artifact hash for asset \"b965ea3084ec95e24846d4975623e62a02c21883c3ddea9366b2ae42d21cef98\"" + "Description": "Artifact hash for asset \"f56a9c742f3e99b26237d5d0912c69f9db8289c13656fdcb490fd017d801c483\"" } }, "Outputs": { diff --git a/packages/@aws-cdk/custom-resources/lib/aws-custom-resource/runtime/index.ts b/packages/@aws-cdk/custom-resources/lib/aws-custom-resource/runtime/index.ts index 56d485e83d4fa..807dc7e78fec5 100644 --- a/packages/@aws-cdk/custom-resources/lib/aws-custom-resource/runtime/index.ts +++ b/packages/@aws-cdk/custom-resources/lib/aws-custom-resource/runtime/index.ts @@ -1,5 +1,11 @@ /* eslint-disable no-console */ import { execSync } from 'child_process'; +// import the AWSLambda package explicitly, +// which is globally available in the Lambda runtime, +// as otherwise linking this repository with link-all.sh +// fails in the CDK app executed with ts-node +/* eslint-disable-next-line import/no-extraneous-dependencies,import/no-unresolved */ +import * as AWSLambda from 'aws-lambda'; import { AwsSdkCall } from '../aws-custom-resource'; /** @@ -204,4 +210,4 @@ export async function handler(event: AWSLambda.CloudFormationCustomResourceEvent function decodeCall(call: string | undefined) { if (!call) { return undefined; } return JSON.parse(call); -} \ No newline at end of file +}