Lambda Execution
AWSim actually executes Lambda function code. It extracts the deployment package, writes a bootstrap wrapper, and runs it as a local process using the system's Node.js or Python interpreter.
Supported Runtimes
| Runtime | Prefix |
|---|---|
| Node.js | nodejs* (e.g., nodejs18.x, nodejs20.x) |
| Python | python* (e.g., python3.11, python3.12) |
Any runtime starting with nodejs invokes node. Any runtime starting with python invokes python3. Other runtimes return an UnsupportedRuntime error.
How It Works
- CreateFunction — AWSim stores the base64-encoded ZIP from
ZipFile(or fetches from S3 ifS3Bucket/S3Keyare provided). - Invoke — AWSim extracts the ZIP to a temp directory, generates a thin bootstrap script, and runs the handler as a subprocess.
- Bootstrap — the wrapper script loads the handler module, passes the event JSON and a context object, and captures stdout as the return value.
- Result — stdout is parsed as the function response. Non-zero exit codes or stderr output is returned as a function error.
Deployment Package Constraints
A deployment package is caller-supplied and is extracted to the local filesystem, so extraction is bounded and contained:
| Constraint | Behaviour |
|---|---|
| Path containment | Every archive member must resolve inside the extraction directory. A member naming ../ or an absolute path is rejected and the whole extraction fails. |
| Symlinks | Symlink members are refused. A symlink pointing outside the extraction directory would let a later member write through it. |
| Unpacked size | Capped at 250 MB, matching the real Lambda unzipped limit. |
| Entry count | Capped at 100,000 members. |
| Function name | Must match [a-zA-Z0-9-_]{1,64}, since the name forms part of the on-disk cache path. |
When extraction is rejected, the error names the offending archive member so the cause is obvious.
Handler Format
The handler is specified as module.function:
index.handler → loads ./index.js, calls exports.handler
src/app.process → loads ./src/app.js, calls exports.processFor Python: app.handler → loads app.py, calls handler(event, context).
Context Object
Your function receives a context object with:
{
functionName: "my-function",
functionVersion: "$LATEST",
invokedFunctionArn: "arn:aws:lambda:...",
memoryLimitInMB: "128",
awsRequestId: "local",
logGroupName: "/aws/lambda/my-function",
logStreamName: "local",
getRemainingTimeInMillis: () => <timeout_ms>,
}Environment Variables
Your function receives the environment variables you configured on the function, plus:
AWS_LAMBDA_FUNCTION_NAMEAWS_LAMBDA_FUNCTION_MEMORY_SIZEAWS_REGIONAWS_DEFAULT_REGION
Deploying a Function
# Package your code
zip function.zip index.js
# Create the function
aws --endpoint-url http://localhost:4566 lambda create-function \
--function-name my-function \
--runtime nodejs20.x \
--handler index.handler \
--role arn:aws:iam::000000000000:role/lambda-role \
--zip-file fileb://function.zip
# Invoke it
aws --endpoint-url http://localhost:4566 lambda invoke \
--function-name my-function \
--payload '{"key":"value"}' \
output.json
cat output.jsonExample: Node.js Handler
// index.js
exports.handler = async (event, context) => {
console.log("Event:", JSON.stringify(event));
return {
statusCode: 200,
body: JSON.stringify({ message: "hello from AWSim Lambda" }),
};
};Example: Python Handler
# handler.py
import json
def handler(event, context):
print("Event:", json.dumps(event))
return {
"statusCode": 200,
"body": json.dumps({"message": "hello from AWSim Lambda"}),
}Known Limitations
- No container/Docker runtime — functions run directly as child processes. There is no isolation between functions or from the host filesystem.
- No Lambda layers execution — layers can be created and listed, but their content is not merged into the function runtime environment.
- No VPC networking — VPC configuration is accepted but ignored.
- Timeout enforcement — the timeout is passed to the context object but is not strictly enforced for long-running functions.
- Node.js require only — the bootstrap uses CommonJS
require(). ESM (import) works only if your runtime supports it natively.