Skip to content

Commit 348de14

Browse files
authored
add support for AWS_ENDPOINT_URL, USE_SSL, and BUCKET_MARKER_LOCAL configurations (#83)
1 parent becde9c commit 348de14

File tree

5 files changed

+24
-15
lines changed

5 files changed

+24
-15
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,5 @@ dist
105105

106106
# TernJS port file
107107
.tern-port
108+
109+
cdk.context.json

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ $ cdklocal --version
2525

2626
The following environment variables can be configured:
2727

28-
* `EDGE_PORT`: Port under which LocalStack edge service is accessible (default: `4566`)
29-
* `LOCALSTACK_HOSTNAME`: Target host under which LocalStack edge service is accessible (default: `localhost`)
28+
* `AWS_ENDPOINT_URL`: The endpoint URL to connect to (combination of `USE_SSL`/`LOCALSTACK_HOSTNAME`/`EDGE_PORT` below)
29+
* `EDGE_PORT` (deprecated): Port under which LocalStack edge service is accessible (default: `4566`)
30+
* `LOCALSTACK_HOSTNAME` (deprecated): Target host under which LocalStack edge service is accessible (default: `localhost`)
31+
* `USE_SSL` (deprecated): Whether to use SSL to connect to the LocalStack endpoint, i.e., connect via HTTPS.
3032
* `LAMBDA_MOUNT_CODE`: Whether to use local Lambda code mounting (via setting `__local__` S3 bucket name). Note: may require CDK version <2.14.0 to be fully functional.
33+
* `BUCKET_MARKER_LOCAL`: Magic S3 bucket name for Lambda mount and [hot reloading](https://docs.localstack.cloud/user-guide/tools/lambda-tools/hot-reloading) (default: `__local__`, will default to `hot-reload` in a future release)
3134

3235
## Deploying a Sample App
3336

@@ -67,6 +70,7 @@ $ awslocal sns list-topics
6770

6871
## Change Log
6972

73+
* 2.18.0: Add support for AWS_ENDPOINT_URL, USE_SSL, and BUCKET_MARKER_LOCAL configurations
7074
* 2.17.0: Fix IPv4 fallback check to prevent IPv6 connection issue with `localhost` on macOS
7175
* 2.16.0: Add check to prevent IPv6 connection issue with `localhost` on MacOS
7276
* 2.15.0: Fix issue with undefined BUCKET_NAME_OUTPUT variable; add CI build and eslint config

bin/cdklocal

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,29 @@ const https = require("https");
99
const crypto = require("crypto");
1010
const net = require('net');
1111

12-
// config constants
12+
// constants and custom config values
13+
14+
const isEnvTrue = (envName) => ["1", "true"].includes(process.env[envName]);
1315

1416
const DEFAULT_EDGE_PORT = 4566;
17+
const EDGE_PORT = process.env.EDGE_PORT || DEFAULT_EDGE_PORT;
1518
const DEFAULT_HOSTNAME = "localhost";
16-
const LAMBDA_MOUNT_CODE = ["1", "true"].includes(process.env.LAMBDA_MOUNT_CODE);
19+
const LAMBDA_MOUNT_CODE = isEnvTrue("LAMBDA_MOUNT_CODE");
20+
const PROTOCOL = isEnvTrue("USE_SSL") ? "https" : "http";
1721

1822

1923
//----------------
2024
// UTIL FUNCTIONS
2125
//----------------
2226

23-
const getLocalEndpoint = async () => `http://${await getLocalHost()}`;
24-
25-
const port = process.env.EDGE_PORT || DEFAULT_EDGE_PORT;
27+
const getLocalEndpoint = async () => process.env.AWS_ENDPOINT_URL || `${PROTOCOL}://${await getLocalHost()}`;
2628

2729
var resolvedHostname = undefined;
2830

2931
const getLocalHost = async () => {
3032
if (resolvedHostname) {
3133
// early exit to not resolve again
32-
return `${resolvedHostname}:${port}`;
34+
return `${resolvedHostname}:${EDGE_PORT}`;
3335
}
3436

3537
var hostname = process.env.LOCALSTACK_HOSTNAME || DEFAULT_HOSTNAME;
@@ -40,15 +42,15 @@ const getLocalHost = async () => {
4042
// Issue: https://github.com/localstack/aws-cdk-local/issues/78
4143
if (hostname === "localhost") {
4244
try {
43-
const options = { host: hostname, port: port };
45+
const options = { host: hostname, port: EDGE_PORT };
4446
await checkTCPConnection(options);
4547
} catch (e) {
4648
hostname = "127.0.0.1";
4749
}
4850
}
4951

5052
resolvedHostname = hostname;
51-
return `${hostname}:${port}`;
53+
return `${hostname}:${EDGE_PORT}`;
5254
};
5355

5456
/**
@@ -204,7 +206,7 @@ const patchToolkitInfo = (ToolkitInfo) => {
204206
async get () {
205207
const bucket = this.requireOutput(BUCKET_NAME_OUTPUT);
206208
const domain = this.requireOutput(BUCKET_DOMAIN_NAME_OUTPUT) || await getLocalHost();
207-
return `https://${domain.replace(`${bucket}.`, "")}:${port}/${bucket}`;
209+
return `https://${domain.replace(`${bucket}.`, "")}:${EDGE_PORT}/${bucket}`;
208210
}
209211
});
210212
};
@@ -257,7 +259,8 @@ const patchLambdaMounting = (CdkToolkit) => {
257259
const paramKey = item.ParameterKey || key;
258260
// TODO: create a more resilient lookup mechanism (not based on "S3Bucket" param key) below!
259261
if (item.ParameterKey && item.ParameterKey.includes("S3Bucket")) {
260-
item.ParameterValue = "__local__";
262+
// TODO: change the default BUCKET_MARKER_LOCAL to 'hot-reload'
263+
item.ParameterValue = process.env.BUCKET_MARKER_LOCAL || '__local__'; // for now, the default is still __local__
261264
}
262265
if (!paramKey.includes("S3VersionKey")) {
263266
return;

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
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.17.0",
4+
"version": "2.18.0",
55
"bin": {
66
"cdklocal": "bin/cdklocal"
77
},

0 commit comments

Comments
 (0)