Skip to content

Commit

Permalink
fix(events-targets): AwsApi is still using Node 16 (#27002)
Browse files Browse the repository at this point in the history
Migrate the `aws-api-handler` code to use SDKv3 and move it into `custom-resource-handlers`.
Updates the Construct config to use the new code and Node18.
To verify functionality, the existing integration test has been extended to include a new rule and target that can be asserted on.

Includes a config change to the `custom-resource-handlers` package to run test from TS.

Closes #26998

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
mrgrain authored Sep 6, 2023
1 parent 0318676 commit 49e5739
Show file tree
Hide file tree
Showing 174 changed files with 43,934 additions and 8,982 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
Expand Down Expand Up @@ -31358,10 +31359,78 @@ var init_find_client_constructor = __esm({
}
});

// ../sdk-v2-to-v3-adapter/lib/sdk-v3-helpers.ts
var sdk_v3_helpers_exports = {};
__export(sdk_v3_helpers_exports, {
getV3Client: () => getV3Client,
getV3Command: () => getV3Command,
loadV3ClientPackage: () => loadV3ClientPackage
});
function loadV3ClientPackage(service) {
const packageName = service.startsWith("@aws-sdk/") ? service : getV3ClientPackageName(service);
try {
const pkg = require(packageName);
const { version: version2 } = require(packageName + "/package.json");
return {
service: packageName.replace("@aws-sdk/client-", ""),
pkg,
packageName,
packageVersion: version2
};
} catch (e) {
throw Error(`Service ${service} client package with name '${packageName}' does not exist.`);
}
}
function getV3Client(sdkPkg, clientOptions = {}) {
try {
const ServiceClient = findV3ClientConstructor(sdkPkg.pkg);
return new ServiceClient(clientOptions);
} catch (e) {
throw Error(`No client constructor found within package: ${sdkPkg.packageName}`);
}
}
function getV3Command(sdkPkg, action) {
const commandName = action.endsWith("Command") ? action : `${action}Command`;
const command = Object.entries(sdkPkg.pkg).find(
([name]) => name.toLowerCase() === commandName.toLowerCase()
)?.[1];
if (!command) {
throw new Error(`Unable to find command named: ${commandName} for api: ${action} in service package`);
}
return command;
}
var init_sdk_v3_helpers = __esm({
"../sdk-v2-to-v3-adapter/lib/sdk-v3-helpers.ts"() {
"use strict";
init_find_client_constructor();
init_get_v3_client_package_name();
}
});

// ../sdk-v2-to-v3-adapter/lib/index.js
var require_lib5 = __commonJS({
"../sdk-v2-to-v3-adapter/lib/index.js"(exports) {
"use strict";
var __createBinding3 = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
if (k2 === void 0)
k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() {
return m[k];
} };
}
Object.defineProperty(o, k2, desc);
} : function(o, m, k, k2) {
if (k2 === void 0)
k2 = k;
o[k2] = m[k];
});
var __exportStar3 = exports && exports.__exportStar || function(m, exports2) {
for (var p in m)
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p))
__createBinding3(exports2, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.findV3ClientConstructor = exports.getV3ClientPackageName = void 0;
var get_v3_client_package_name_1 = (init_get_v3_client_package_name(), __toCommonJS(get_v3_client_package_name_exports));
Expand All @@ -31372,6 +31441,7 @@ var require_lib5 = __commonJS({
Object.defineProperty(exports, "findV3ClientConstructor", { enumerable: true, get: function() {
return find_client_constructor_1.findV3ClientConstructor;
} });
__exportStar3((init_sdk_v3_helpers(), __toCommonJS(sdk_v3_helpers_exports)), exports);
}
});

Expand All @@ -31395,6 +31465,7 @@ var CustomResourceHandler = class {
constructor(event, context) {
this.event = event;
this.context = context;
this.timedOut = false;
this.timeout = setTimeout(async () => {
await this.respond({
status: "FAILED",
Expand All @@ -31406,9 +31477,6 @@ var CustomResourceHandler = class {
this.event = event;
this.physicalResourceId = extractPhysicalResourceId(event);
}
physicalResourceId;
timeout;
timedOut = false;
/**
* Handles executing the custom resource event. If `stateMachineArn` is present
* in the props then trigger the waiter statemachine
Expand Down Expand Up @@ -31542,7 +31610,6 @@ var AssertionHandler = class extends CustomResourceHandler {
}
};
var MatchCreator = class {
parsedObj;
constructor(obj) {
this.parsedObj = {
matcher: obj
Expand Down Expand Up @@ -31674,14 +31741,11 @@ var import_sdk_v2_to_v3_adapter = __toESM(require_lib5());

// lib/assertions/providers/lambda-handler/utils.ts
function parseJsonPayload(payload) {
const text = new TextDecoder().decode(Buffer.from(payload ?? ""));
if (!text) {
return {};
}
try {
return JSON.parse(text);
const buffer = Buffer.from(payload);
return JSON.parse(new TextDecoder().decode(buffer));
} catch {
throw new Error(`return values from user-handlers must be JSON objects. got: "${text}"`);
return payload;
}
}
function decodeParameters(obj) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,10 +532,78 @@ var init_find_client_constructor = __esm({
}
});

// ../@aws-cdk/sdk-v2-to-v3-adapter/lib/sdk-v3-helpers.ts
var sdk_v3_helpers_exports = {};
__export(sdk_v3_helpers_exports, {
getV3Client: () => getV3Client,
getV3Command: () => getV3Command,
loadV3ClientPackage: () => loadV3ClientPackage
});
function loadV3ClientPackage(service) {
const packageName = service.startsWith("@aws-sdk/") ? service : getV3ClientPackageName(service);
try {
const pkg = require(packageName);
const { version } = require(packageName + "/package.json");
return {
service: packageName.replace("@aws-sdk/client-", ""),
pkg,
packageName,
packageVersion: version
};
} catch (e) {
throw Error(`Service ${service} client package with name '${packageName}' does not exist.`);
}
}
function getV3Client(sdkPkg, clientOptions = {}) {
try {
const ServiceClient = findV3ClientConstructor(sdkPkg.pkg);
return new ServiceClient(clientOptions);
} catch (e) {
throw Error(`No client constructor found within package: ${sdkPkg.packageName}`);
}
}
function getV3Command(sdkPkg, action) {
const commandName = action.endsWith("Command") ? action : `${action}Command`;
const command = Object.entries(sdkPkg.pkg).find(
([name]) => name.toLowerCase() === commandName.toLowerCase()
)?.[1];
if (!command) {
throw new Error(`Unable to find command named: ${commandName} for api: ${action} in service package`);
}
return command;
}
var init_sdk_v3_helpers = __esm({
"../@aws-cdk/sdk-v2-to-v3-adapter/lib/sdk-v3-helpers.ts"() {
"use strict";
init_find_client_constructor();
init_get_v3_client_package_name();
}
});

// ../@aws-cdk/sdk-v2-to-v3-adapter/lib/index.js
var require_lib = __commonJS({
"../@aws-cdk/sdk-v2-to-v3-adapter/lib/index.js"(exports) {
"use strict";
var __createBinding = exports && exports.__createBinding || (Object.create ? function(o, m, k, k2) {
if (k2 === void 0)
k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() {
return m[k];
} };
}
Object.defineProperty(o, k2, desc);
} : function(o, m, k, k2) {
if (k2 === void 0)
k2 = k;
o[k2] = m[k];
});
var __exportStar = exports && exports.__exportStar || function(m, exports2) {
for (var p in m)
if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports2, p))
__createBinding(exports2, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.findV3ClientConstructor = exports.getV3ClientPackageName = void 0;
var get_v3_client_package_name_1 = (init_get_v3_client_package_name(), __toCommonJS(get_v3_client_package_name_exports));
Expand All @@ -546,6 +614,7 @@ var require_lib = __commonJS({
Object.defineProperty(exports, "findV3ClientConstructor", { enumerable: true, get: function() {
return find_client_constructor_1.findV3ClientConstructor;
} });
__exportStar((init_sdk_v3_helpers(), __toCommonJS(sdk_v3_helpers_exports)), exports);
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"version": "34.0.0",
"files": {
"5f29389ceebe277aadade8a9e7583fdd274a2a2f2d6adf410243bea23c244b9d": {
"d64690b87ee4eb4d8bbabafe26f88d8cc557bb629a158ed5fb182b8e48da1bbf": {
"source": {
"path": "asset.5f29389ceebe277aadade8a9e7583fdd274a2a2f2d6adf410243bea23c244b9d",
"path": "asset.d64690b87ee4eb4d8bbabafe26f88d8cc557bb629a158ed5fb182b8e48da1bbf",
"packaging": "zip"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "5f29389ceebe277aadade8a9e7583fdd274a2a2f2d6adf410243bea23c244b9d.zip",
"objectKey": "d64690b87ee4eb4d8bbabafe26f88d8cc557bb629a158ed5fb182b8e48da1bbf.zip",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand All @@ -27,15 +27,15 @@
}
}
},
"7d2e082c72721d0c18fe04449320a9c2714679815c66afa2326da57244b8f2a2": {
"f9d7a609d78100aca72b5fe61c968d55e9fc580b4a61d89e622350fabdcb4da6": {
"source": {
"path": "integ-cognito.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "7d2e082c72721d0c18fe04449320a9c2714679815c66afa2326da57244b8f2a2.json",
"objectKey": "f9d7a609d78100aca72b5fe61c968d55e9fc580b4a61d89e622350fabdcb4da6.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "5f29389ceebe277aadade8a9e7583fdd274a2a2f2d6adf410243bea23c244b9d.zip"
"S3Key": "d64690b87ee4eb4d8bbabafe26f88d8cc557bb629a158ed5fb182b8e48da1bbf.zip"
},
"Handler": "index.handler",
"Role": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
{
"version": "34.0.0",
"files": {
"ba11e38264ca2aa7e3526744e71e22c78bd856cbfd0b4d7e089ee2ccf6d4e928": {
"92519e926ac4ba644c6184363d536269cb0557fe7acc3593ae702e5a8b8e81a2": {
"source": {
"path": "asset.ba11e38264ca2aa7e3526744e71e22c78bd856cbfd0b4d7e089ee2ccf6d4e928.bundle",
"path": "asset.92519e926ac4ba644c6184363d536269cb0557fe7acc3593ae702e5a8b8e81a2.bundle",
"packaging": "zip"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "ba11e38264ca2aa7e3526744e71e22c78bd856cbfd0b4d7e089ee2ccf6d4e928.zip",
"objectKey": "92519e926ac4ba644c6184363d536269cb0557fe7acc3593ae702e5a8b8e81a2.zip",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
},
"6d7b07a6b2af8996027b6eaddd9800cefa75bec62058cfe12c0ee5e2f11953a4": {
"c42eb6e89441b92158b8079ee0a6323db61c7c6e1c4cee046b8899317ed64983": {
"source": {
"path": "integtestcognitoDefaultTestDeployAssert6F2623C9.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "6d7b07a6b2af8996027b6eaddd9800cefa75bec62058cfe12c0ee5e2f11953a4.json",
"objectKey": "c42eb6e89441b92158b8079ee0a6323db61c7c6e1c4cee046b8899317ed64983.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
}
},
"flattenResponse": "false",
"salt": "1693922024206"
"salt": "1694000253228"
},
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
Expand Down Expand Up @@ -127,7 +127,7 @@
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "ba11e38264ca2aa7e3526744e71e22c78bd856cbfd0b4d7e089ee2ccf6d4e928.zip"
"S3Key": "92519e926ac4ba644c6184363d536269cb0557fe7acc3593ae702e5a8b8e81a2.zip"
},
"Timeout": 120,
"Handler": "index.handler",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/7d2e082c72721d0c18fe04449320a9c2714679815c66afa2326da57244b8f2a2.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/f9d7a609d78100aca72b5fe61c968d55e9fc580b4a61d89e622350fabdcb4da6.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
Expand Down Expand Up @@ -316,7 +316,7 @@
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/6d7b07a6b2af8996027b6eaddd9800cefa75bec62058cfe12c0ee5e2f11953a4.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/c42eb6e89441b92158b8079ee0a6323db61c7c6e1c4cee046b8899317ed64983.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@
"s3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"s3Key": "5f29389ceebe277aadade8a9e7583fdd274a2a2f2d6adf410243bea23c244b9d.zip"
"s3Key": "d64690b87ee4eb4d8bbabafe26f88d8cc557bb629a158ed5fb182b8e48da1bbf.zip"
},
"handler": "index.handler",
"role": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
}
}
},
"5f29389ceebe277aadade8a9e7583fdd274a2a2f2d6adf410243bea23c244b9d": {
"d64690b87ee4eb4d8bbabafe26f88d8cc557bb629a158ed5fb182b8e48da1bbf": {
"source": {
"path": "asset.5f29389ceebe277aadade8a9e7583fdd274a2a2f2d6adf410243bea23c244b9d",
"path": "asset.d64690b87ee4eb4d8bbabafe26f88d8cc557bb629a158ed5fb182b8e48da1bbf",
"packaging": "zip"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "5f29389ceebe277aadade8a9e7583fdd274a2a2f2d6adf410243bea23c244b9d.zip",
"objectKey": "d64690b87ee4eb4d8bbabafe26f88d8cc557bb629a158ed5fb182b8e48da1bbf.zip",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand All @@ -40,15 +40,15 @@
}
}
},
"781b96e677727c9014cc997450cc3f665e25a51c1d4c425f8c3a63582cc2a9bd": {
"ad72caaa8b80f2a6a7f4ac8cd7d7d967be4712cf0ee0fd11951c6df0a91c54b3": {
"source": {
"path": "IntegAlbOidc.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "781b96e677727c9014cc997450cc3f665e25a51c1d4c425f8c3a63582cc2a9bd.json",
"objectKey": "ad72caaa8b80f2a6a7f4ac8cd7d7d967be4712cf0ee0fd11951c6df0a91c54b3.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}"
},
"S3Key": "5f29389ceebe277aadade8a9e7583fdd274a2a2f2d6adf410243bea23c244b9d.zip"
"S3Key": "d64690b87ee4eb4d8bbabafe26f88d8cc557bb629a158ed5fb182b8e48da1bbf.zip"
},
"Handler": "index.handler",
"Role": {
Expand Down
Loading

0 comments on commit 49e5739

Please sign in to comment.