Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.
Python awsaws-emulatoraws-localaws-sdkdevtoolsdockerdynamodbec2emulatorlambdalocalstacklocalstack-alternativeministackmock-awsopen-sourcepythons3sqsterraform
fix(lambda): start Node.js and Python functions in the code directory (#1968)
Younes Berianeaafe4ac9419b
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex d87ef1b7..0faffa80 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -26,6 +26,7 @@ Versioning follows [Semantic Versioning](https://semver.org/).### Fixed+- **Lambda — Node.js and Python functions start in the code directory** — `process.cwd()` and `os.getcwd()` were MiniStack's own working directory, so libraries that read files relative to the cwd (e.g. `node-config`) missed the function's code; the cwd is now the extracted code root, as `LAMBDA_TASK_ROOT` on AWS- **CloudFormation — nested stack with a `Transform`** — where `Capabilities` are checked, a nested stack whose template declares a `Transform` or calls `Fn::Transform` fails with `Requires capabilities : [CAPABILITY_AUTO_EXPAND]` unless the parent acknowledged `CAPABILITY_AUTO_EXPAND`, as on AWS.- **CloudFormation — `AWS::RDS::DBCluster` and `AWS::RDS::DBInstance` update in place** — a stack update re-ran the create, which gave the resource a new endpoint, resource id and create time and emptied the cluster's member list; the properties the create stores now change on the existing record, a create-only or `Engine` change replaces the resource or, under a custom identifier, is refused, a cluster `MasterUsername` change leaves the cluster as it is, change sets report which properties replace, and a stack-created cluster can now be described and answers `Fn::GetAtt DBClusterResourceId`. Contributed by @iot-rocket.- **SES — a sandboxed account sends only to verified or simulator recipients** — SES v2 `PutAccountDetails` with `ProductionAccessEnabled=false` puts the account (per region) in the sandbox, as on AWS, and `GetAccount` reports it with the submitted `Details`. A sandboxed send to a recipient that is neither a verified address or domain identity nor a `@simulator.amazonses.com` address fails with `MessageRejected` "Email address is not verified. The following identities failed the check in region …" for v1 `SendEmail`, `SendRawEmail` and `SendTemplatedEmail` and v2 `SendEmail`; bulk sends reject only the affected entries. Accounts stay in production by default. Reported by @skialpine.diff --git a/ministack/core/lambda_runtime.py b/ministack/core/lambda_runtime.pyindex 733bfaea..cefe8fe1 100644--- a/ministack/core/lambda_runtime.py+++ b/ministack/core/lambda_runtime.py@@ -1225,6 +1225,7 @@ class Worker:self._proc = subprocess.Popen([binary, worker_path],+ cwd=code_dir,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,diff --git a/ministack/services/lambda_svc.py b/ministack/services/lambda_svc.pyindex 9c134a78..b1a56523 100644--- a/ministack/services/lambda_svc.py+++ b/ministack/services/lambda_svc.py@@ -5686,6 +5686,7 @@ def _execute_function_local(func: dict, event: dict) -> dict:text=True,timeout=timeout,env=env,+ cwd=code_dir,)log_tail = proc.stderr.strip()diff --git a/tests/test_lambda_runtime_worker.py b/tests/test_lambda_runtime_worker.pyindex ac9c943e..80498285 100644--- a/tests/test_lambda_runtime_worker.py+++ b/tests/test_lambda_runtime_worker.py@@ -405,3 +405,18 @@ exports.handler = async () => ({ ok: true });assert "@aws-sdk/client-no-local-stub" in messageassert "LAMBDA_EXECUTOR=docker" in messageassert "Cannot find module" not in message++[email protected](shutil.which("node") is None, reason="Node.js is not installed")+def test_node_worker_cwd_is_code_dir():+ """process.cwd() must be the extracted code root, as on AWS (LAMBDA_TASK_ROOT)."""+ worker = _node_worker(+ "exports.handler = async () => ({ cwd: process.cwd(), root: process.env.LAMBDA_TASK_ROOT });"+ )+ try:+ result = worker.invoke({}, request_id="cwd-request-id")+ finally:+ worker.kill()++ assert result["status"] == "ok", result+ assert result["result"]["cwd"] == result["result"]["root"]