Skip to content

Commit

Permalink
Merge pull request #92 from localstack/missing_aws_cdk_exception
Browse files Browse the repository at this point in the history
Throw somewhat better exception if aws-cdk is missing
  • Loading branch information
lakkeger authored Sep 26, 2024
2 parents 348de14 + 98ce115 commit 3704bb4
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 20 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/integrations.go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ jobs:
# The AWS CDK only supports third-party languages "until its EOL (End Of Life) shared by the vendor or community"
# https://github.com/aws/aws-cdk
# Golang EOL overview: https://endoflife.date/go
- { language: go, node-version: '16.x', go-version: '1.17.8', region: us-east-1}
- { language: go, node-version: '16.x', go-version: '1.18', region: us-east-1}
- { language: go, node-version: '18.x', go-version: '1.20', region: us-east-1}
- { language: go, node-version: '18.x', go-version: '1.18', region: us-east-1}
- { language: go, node-version: '20.x', go-version: '1.20', region: us-east-1}
- { language: go, node-version: '22.x', go-version: '1.22', region: us-east-1}

env:
AWS_REGION: ${{ matrix.region }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/integrations.node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
strategy:
matrix:
include:
- { language: javascript, node-version: '16.x', region: us-east-1}
- { language: typescript, node-version: '16.x', region: eu-west-2}
- { language: typescript, node-version: '16.x', region: us-east-1}
- { language: typescript, node-version: '14.x', region: us-east-1}
- { language: javascript, node-version: '18.x', region: us-east-1}
- { language: typescript, node-version: '20.x', region: eu-west-2}
- { language: typescript, node-version: '21.x', region: us-east-1}
- { language: typescript, node-version: '22.x', region: us-east-1}

env:
AWS_REGION: ${{ matrix.region }}
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/integrations.python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ jobs:
strategy:
matrix:
include:
- { language: python, node-version: '16.x', python-version: '3.10', region: us-east-1}
- { language: python, node-version: '16.x', python-version: '3.9', region: us-east-1}
- { language: python, node-version: '16.x', python-version: '3.8', region: us-east-1}
- { language: python, node-version: '18.x', python-version: '3.9', region: us-east-1}
- { language: python, node-version: '20.x', python-version: '3.10', region: us-east-1}
- { language: python, node-version: '21.x', python-version: '3.11', region: us-east-1}
- { language: python, node-version: '22.x', python-version: '3.12', region: us-east-1}

env:
AWS_REGION: ${{ matrix.region }}
Expand Down
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This project provides a thin wrapper script `cdklocal` for using the [AWS CDK](h
## Quick Installation

The `cdklocal` command line is published as an [npm library](https://www.npmjs.com/package/aws-cdk-local):
```
```bash
$ npm install -g aws-cdk-local aws-cdk
...
$ cdklocal --version
Expand All @@ -21,6 +21,13 @@ $ cdklocal --version

(Note: Depending on your local setup, you may or may not have to use the global `npm` installation flag `-g` above.)

### Mac OS specific `MODULE_NOT_FOUND` issue
On Mac OS, brew can be used to install AWS CDK, which might result in a `MODULE_NOT_FOUND` error from `cdklocal`.
To resolve this, set the `NODE_PATH` variable pointing to your AWS CDK's `node_module` folder to expand the lookup path for modules.
```bash
$ export NODE_PATH=$NODE_PATH:/opt/homebrew/Cellar/aws-cdk/<CDK_VERSION>/libexec/lib/node_modules
```

## Configurations

The following environment variables can be configured:
Expand All @@ -35,19 +42,19 @@ The following environment variables can be configured:
## Deploying a Sample App

The CDK command line ships with a sample app generator to run a quick test for getting started:
```
```bash
$ mkdir /tmp/test; cd /tmp/test
$ cdklocal init sample-app --language=javascript
...
```

Make sure that LocalStack is installed and started up with the required services:
```
```bash
$ SERVICES=serverless,sqs,sns localstack start
```

Then deploy the sample app against the local APIs via the `cdklocal` command line:
```
```bash
$ cdklocal deploy
...
Do you wish to deploy these changes (y/n)? y
Expand All @@ -57,7 +64,7 @@ arn:aws:cloudformation:us-east-1:000000000000:stack/TestStack/e3debc0a-311e-4968
```

Once the deployment is done, you can inspect the created resources via the [`awslocal`](https://github.com/localstack/awscli-local) command line:
```
```bash
$ awslocal sns list-topics
{
"Topics": [
Expand All @@ -70,6 +77,7 @@ $ awslocal sns list-topics

## Change Log

* 2.18.1: Throw better exception if `aws-cdk` not found
* 2.18.0: Add support for AWS_ENDPOINT_URL, USE_SSL, and BUCKET_MARKER_LOCAL configurations
* 2.17.0: Fix IPv4 fallback check to prevent IPv6 connection issue with `localhost` on macOS
* 2.16.0: Add check to prevent IPv6 connection issue with `localhost` on MacOS
Expand Down
24 changes: 22 additions & 2 deletions bin/cdklocal
Original file line number Diff line number Diff line change
Expand Up @@ -363,16 +363,36 @@ const applyPatches = (provider, CdkToolkit, SDK, ToolkitInfo, patchAssets = true
};

const patchPre_2_14 = () => {
const provider = require("aws-cdk/lib/api/aws-auth");
var provider = null;
try {
provider = require("aws-cdk/lib/api/aws-auth");
} catch(e) {
if (e.code == "MODULE_NOT_FOUND") {
console.log(e);
console.error("`aws-cdk` module NOT found! Have you tried adding it to your `NODE_PATH`?");
throw e;
}
}

const {CdkToolkit} = require("aws-cdk/lib/cdk-toolkit");
const {SDK} = require("aws-cdk/lib/api/aws-auth/sdk");
const {ToolkitInfo} = require("aws-cdk/lib/api");


applyPatches(provider, CdkToolkit, SDK, ToolkitInfo);
};

const patchPost_2_14 = () => {
const lib = require("aws-cdk/lib");
var lib = null;
try {
lib = require("aws-cdk/lib");
} catch(e) {
if (e.code == "MODULE_NOT_FOUND") {
console.log(e);
console.log("`aws-cdk` module NOT found! Have you tried to add it to your `NODE_PATH`?");
process.exit(1);
}
}

applyPatches(lib, lib, lib.SDK, lib.ToolkitInfo, false);
};
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "aws-cdk-local",
"description": "CDK Toolkit for use with LocalStack",
"version": "2.18.0",
"version": "2.18.1",
"bin": {
"cdklocal": "bin/cdklocal"
},
Expand Down

0 comments on commit 3704bb4

Please sign in to comment.