Skip to content

Commit 7400aa3

Browse files
authored
Fix: support aws-cdk>=2.177.0 (#107)
1 parent 1befa15 commit 7400aa3

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
id: simple-matrix
4848
if: ${{ inputs.run-all-latest-cdk-versions == false }}
4949
run: |
50-
export VERSIONS_ARRAY='["2.30.0", "2.50.0", "2.75.0", "2.120.0", "2.166.0", "2.167.0", ""]'
50+
export VERSIONS_ARRAY='["2.30.0", "2.50.0", "2.75.0", "2.120.0", "2.166.0", "2.167.0", "2.177.0", ""]'
5151
echo "VERSIONS_ARRAY=$VERSIONS_ARRAY" >> $GITHUB_ENV
5252
5353
- name: Generate matrix

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ $ export NODE_PATH=$NODE_PATH:/opt/homebrew/Cellar/aws-cdk/<CDK_VERSION>/libexec
3333
The following environment variables can be configured:
3434

3535
* `AWS_ENDPOINT_URL`: The endpoint URL to connect to (combination of `USE_SSL`/`LOCALSTACK_HOSTNAME`/`EDGE_PORT` below)
36+
* `AWS_ENDPOINT_URL_S3`: The endpoint URL to connect to (combination of `USE_SSL`/`LOCALSTACK_HOSTNAME`/`EDGE_PORT` below) for S3 requests
3637
* `EDGE_PORT` (deprecated): Port under which LocalStack edge service is accessible (default: `4566`)
3738
* `LOCALSTACK_HOSTNAME` (deprecated): Target host under which LocalStack edge service is accessible (default: `localhost`)
3839
* `USE_SSL` (deprecated): Whether to use SSL to connect to the LocalStack endpoint, i.e., connect via HTTPS.
@@ -77,6 +78,7 @@ $ awslocal sns list-topics
7778

7879
## Change Log
7980

81+
* 2.19.2: Fix SDK compatibility with aws-cdk versions >= 2.177.0
8082
* 2.19.1: Fix SDK compatibility with older CDK versions; Fix patched bucket location in TemplateURL
8183
* 2.19.0: Add support for aws-cdk versions >= `2.167.0`
8284
* 2.18.1: Throw better exception if `aws-cdk` not found

bin/cdklocal

+29-2
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ const patchToolkitInfo = (ToolkitInfo) => {
252252
await prefetchBucketUrl(toolkitInfoObject);
253253
return toolkitInfoObject;
254254
};
255-
255+
256256
const fromStackFn = ToolkitInfo.fromStack;
257257
ToolkitInfo.fromStack = (...args) => {
258258
const toolkitInfoObject = fromStackFn(...args);
@@ -451,6 +451,13 @@ const patchPre_2_14 = () => {
451451
applyPatches(provider, CdkToolkit, SDK, ToolkitInfo);
452452
};
453453

454+
const configureEnvironment = () => {
455+
// This _must_ use localhost.localstack.cloud as we require valid subdomains of these paths to
456+
// resolve. Unfortunately though `curl` seems to support subdomains of localhost, the CDK does not.
457+
process.env.AWS_ENDPOINT_URL_S3 = process.env.AWS_ENDPOINT_URL_S3 || `${PROTOCOL}://s3.localhost.localstack.cloud:${EDGE_PORT}`;
458+
process.env.AWS_ENDPOINT_URL = process.env.AWS_ENDPOINT_URL || `${PROTOCOL}://localhost.localstack.cloud:${EDGE_PORT}`;
459+
};
460+
454461
const patchPost_2_14 = () => {
455462
var lib = null;
456463
try {
@@ -463,7 +470,27 @@ const patchPost_2_14 = () => {
463470
}
464471
}
465472

466-
applyPatches(lib, lib, lib.SDK, lib.ToolkitInfo, false);
473+
// detect if we are using version 2.177.0 or later. This version has reorganised the package
474+
// structure so that we cannot import and patch the aws-cdk package as we did for versions
475+
// <2.177.0. We use the specific error raised by the node require system to determine if we are
476+
// using pre or post 2.177.0.
477+
try {
478+
require("aws-cdk/lib/legacy-exports");
479+
} catch (e) {
480+
switch (e.code) {
481+
case "MODULE_NOT_FOUND":
482+
// pre 2.177
483+
applyPatches(lib, lib, lib.SDK, lib.ToolkitInfo, false);
484+
break;
485+
case "ERR_PACKAGE_PATH_NOT_EXPORTED":
486+
// post 2.177
487+
configureEnvironment();
488+
break;
489+
default:
490+
// a different error
491+
throw e
492+
}
493+
}
467494
};
468495

469496
if (isEsbuildBundle()) {

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "aws-cdk-local",
33
"description": "CDK Toolkit for use with LocalStack",
4-
"version": "2.19.1",
4+
"version": "2.19.2",
55
"bin": {
66
"cdklocal": "bin/cdklocal"
77
},

0 commit comments

Comments
 (0)