diff --git a/.gitignore b/.gitignore index 8320cf0..659ae94 100644 --- a/.gitignore +++ b/.gitignore @@ -105,3 +105,5 @@ dist # TernJS port file .tern-port + +cdk.context.json diff --git a/README.md b/README.md index dff17bc..33d529c 100644 --- a/README.md +++ b/README.md @@ -25,9 +25,12 @@ $ cdklocal --version The following environment variables can be configured: -* `EDGE_PORT`: Port under which LocalStack edge service is accessible (default: `4566`) -* `LOCALSTACK_HOSTNAME`: Target host under which LocalStack edge service is accessible (default: `localhost`) +* `AWS_ENDPOINT_URL`: The endpoint URL to connect to (combination of `USE_SSL`/`LOCALSTACK_HOSTNAME`/`EDGE_PORT` below) +* `EDGE_PORT` (deprecated): Port under which LocalStack edge service is accessible (default: `4566`) +* `LOCALSTACK_HOSTNAME` (deprecated): Target host under which LocalStack edge service is accessible (default: `localhost`) +* `USE_SSL` (deprecated): Whether to use SSL to connect to the LocalStack endpoint, i.e., connect via HTTPS. * `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. +* `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) ## Deploying a Sample App @@ -67,6 +70,7 @@ $ awslocal sns list-topics ## Change Log +* 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 * 2.15.0: Fix issue with undefined BUCKET_NAME_OUTPUT variable; add CI build and eslint config diff --git a/bin/cdklocal b/bin/cdklocal index 67134a7..d56c295 100755 --- a/bin/cdklocal +++ b/bin/cdklocal @@ -9,27 +9,29 @@ const https = require("https"); const crypto = require("crypto"); const net = require('net'); -// config constants +// constants and custom config values + +const isEnvTrue = (envName) => ["1", "true"].includes(process.env[envName]); const DEFAULT_EDGE_PORT = 4566; +const EDGE_PORT = process.env.EDGE_PORT || DEFAULT_EDGE_PORT; const DEFAULT_HOSTNAME = "localhost"; -const LAMBDA_MOUNT_CODE = ["1", "true"].includes(process.env.LAMBDA_MOUNT_CODE); +const LAMBDA_MOUNT_CODE = isEnvTrue("LAMBDA_MOUNT_CODE"); +const PROTOCOL = isEnvTrue("USE_SSL") ? "https" : "http"; //---------------- // UTIL FUNCTIONS //---------------- -const getLocalEndpoint = async () => `http://${await getLocalHost()}`; - -const port = process.env.EDGE_PORT || DEFAULT_EDGE_PORT; +const getLocalEndpoint = async () => process.env.AWS_ENDPOINT_URL || `${PROTOCOL}://${await getLocalHost()}`; var resolvedHostname = undefined; const getLocalHost = async () => { if (resolvedHostname) { // early exit to not resolve again - return `${resolvedHostname}:${port}`; + return `${resolvedHostname}:${EDGE_PORT}`; } var hostname = process.env.LOCALSTACK_HOSTNAME || DEFAULT_HOSTNAME; @@ -40,7 +42,7 @@ const getLocalHost = async () => { // Issue: https://github.com/localstack/aws-cdk-local/issues/78 if (hostname === "localhost") { try { - const options = { host: hostname, port: port }; + const options = { host: hostname, port: EDGE_PORT }; await checkTCPConnection(options); } catch (e) { hostname = "127.0.0.1"; @@ -48,7 +50,7 @@ const getLocalHost = async () => { } resolvedHostname = hostname; - return `${hostname}:${port}`; + return `${hostname}:${EDGE_PORT}`; }; /** @@ -204,7 +206,7 @@ const patchToolkitInfo = (ToolkitInfo) => { async get () { const bucket = this.requireOutput(BUCKET_NAME_OUTPUT); const domain = this.requireOutput(BUCKET_DOMAIN_NAME_OUTPUT) || await getLocalHost(); - return `https://${domain.replace(`${bucket}.`, "")}:${port}/${bucket}`; + return `https://${domain.replace(`${bucket}.`, "")}:${EDGE_PORT}/${bucket}`; } }); }; @@ -257,7 +259,8 @@ const patchLambdaMounting = (CdkToolkit) => { const paramKey = item.ParameterKey || key; // TODO: create a more resilient lookup mechanism (not based on "S3Bucket" param key) below! if (item.ParameterKey && item.ParameterKey.includes("S3Bucket")) { - item.ParameterValue = "__local__"; + // TODO: change the default BUCKET_MARKER_LOCAL to 'hot-reload' + item.ParameterValue = process.env.BUCKET_MARKER_LOCAL || '__local__'; // for now, the default is still __local__ } if (!paramKey.includes("S3VersionKey")) { return; diff --git a/package-lock.json b/package-lock.json index f349d76..35e808a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "aws-cdk-local", - "version": "2.17.0", + "version": "2.18.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "aws-cdk-local", - "version": "2.17.0", + "version": "2.18.0", "license": "Apache-2.0", "dependencies": { "diff": "^5.0.0" diff --git a/package.json b/package.json index 11e9748..7a8ccd6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "aws-cdk-local", "description": "CDK Toolkit for use with LocalStack", - "version": "2.17.0", + "version": "2.18.0", "bin": { "cdklocal": "bin/cdklocal" },