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

Throw somewhat better exception if aws-cdk is missing #92

Merged
merged 3 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 could be used to install AWS CDK, which will result in a `MODULE_NOT_FOUND` error from `cdklocal`.
lakkeger marked this conversation as resolved.
Show resolved Hide resolved
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.log("`aws-cdk` module NOT found! Have you tried to add it to your `NODE_PATH`?");
lakkeger marked this conversation as resolved.
Show resolved Hide resolved
process.exit(1);
lakkeger marked this conversation as resolved.
Show resolved Hide resolved
}
}

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
Loading