Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
54a76ca
refactor: :recycle: adding a new script that selectively builds speci…
Feb 19, 2026
2cbcb4f
refactor: :recycle: add a custom lambda-entrypoint to select differen…
Feb 19, 2026
7aa7c0b
refactor: :recycle: modifying dockerfile to include both the build sc…
Feb 19, 2026
9eb1b46
refactor: :recycle add nuke continaers to the makefile
Feb 19, 2026
8ce868b
test: :sparkles: add harness testing capability
Feb 20, 2026
72f658e
refactor: :recycle: some small fixes
Feb 20, 2026
2b40b80
chore: putting permission read
Feb 20, 2026
7078074
chore: add readme for test-dockerized
Feb 20, 2026
eff6892
chore: removing unused file
Feb 20, 2026
5f04820
chore: removed unused file
Feb 20, 2026
d021b48
refactor: :recycle: moving the environmental variables in a dedicated…
Feb 20, 2026
fbfa5e5
removing docker_buildkit
Feb 20, 2026
cf33209
chore: change the workflow version
Feb 20, 2026
82b5386
chore: setting up python 3.11
Feb 23, 2026
36dea96
chore: fix problem with test
Feb 23, 2026
f902d5b
chore: syncing local and remote build
Feb 23, 2026
cb343de
chore: trying to source the env variable file
Feb 23, 2026
d7ce866
chore: inspecting the image in the docker actions
Feb 23, 2026
b79909b
chore: add another test to check potential errors
Feb 23, 2026
d5c8bd7
chore: another test
Feb 23, 2026
0c7dedb
chore: see what happens to the test action if I'm putting 5 seconds t…
Feb 23, 2026
68b38a4
chore: another manual test
Feb 23, 2026
5916174
chore: putting the port mapping back and trying with one second timeout
Feb 23, 2026
0998923
chore: setting debugger on
Feb 23, 2026
f2e2370
chore: modifying the makefile to adapt it to the new test runner
Feb 24, 2026
d7595ec
chore: fix error in github actions
Feb 24, 2026
838ac57
chore: some more changes
Feb 24, 2026
2103e0e
chore: fix backward compatibility with previous tests
Feb 24, 2026
fda045c
chore: fix issue in github actions
Feb 24, 2026
50666bc
chore: other fixes
Feb 25, 2026
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
13 changes: 13 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Test configuration for RIE and dockerized tests
# Customize these values as needed for testing both local and on github

# Handlers to build
HANDLERS_TO_BUILD=basic-lambda

HANDLER=basic-lambda

# Output directory for built binaries
OUTPUT_DIR=test/dockerized/tasks

# Max concurrent Lambda invocations for LMI mode
RIE_MAX_CONCURRENCY=4
47 changes: 47 additions & 0 deletions .github/workflows/dockerized-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: dockerized-test

permissions:
contents: read

on:
push:
branches: [ main ]
pull_request:
branches: [ '*' ]
workflow_dispatch:


jobs:
dockerized-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6

- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Load environment variables
run: |
if [ -f .env ]; then
set -a
source .env
set +a
echo "HANDLERS_TO_BUILD=${HANDLERS_TO_BUILD}" >> $GITHUB_ENV
echo "OUTPUT_DIR=${OUTPUT_DIR}" >> $GITHUB_ENV
fi
- name: Build Lambda artifacts for testing
run: |
mkdir -p test/dockerized/tasks
OUTPUT_DIR="$(pwd)/test/dockerized/tasks" make build-examples
ls -la test/dockerized/tasks/
- name: Build base test image with RIE and custom entrypoint
run: |
docker build . -t local/test-base -f Dockerfile.test
- name: Run tests
uses: aws/containerized-test-runner-for-aws-lambda@main
with:
suiteFileArray: '["./test/dockerized/suites/*.json"]'
dockerImageName: 'local/test-base'
taskFolder: './test/dockerized/tasks'
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ target
lambda-runtime/libtest.rmeta
lambda-integration-tests/target
Cargo.lock
.test-runner

# Built AWS Lambda zipfile
lambda.zip
Expand All @@ -16,3 +17,7 @@ build

node_modules
cdk.out

# Test artifacts
Dockerfile.test-with-tasks
test/dockerized/tasks/
10 changes: 10 additions & 0 deletions Dockerfile.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM public.ecr.aws/lambda/provided:al2023

ADD https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie /usr/local/bin/aws-lambda-rie
RUN chmod +x /usr/local/bin/aws-lambda-rie

COPY scripts/custom-lambda-entrypoint.sh /usr/local/bin/lambda-entrypoint
RUN chmod +x /usr/local/bin/lambda-entrypoint

ENTRYPOINT ["/usr/local/bin/lambda-entrypoint"]
CMD ["basic-lambda"]
74 changes: 72 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ INTEG_EXTENSIONS := extension-fn extension-trait logs-trait
# Using musl to run extensions on both AL1 and AL2
INTEG_ARCH := x86_64-unknown-linux-musl
RIE_MAX_CONCURRENCY ?= 4
OUTPUT_DIR ?= test/dockerized/tasks
HANDLERS_TO_BUILD ?=
HANDLER ?=

# Load environment variables from .env file if it exists
-include .env
export

.PHONY: help pr-check integration-tests check-event-features fmt build-examples test-rie test-rie-lmi nuke test-dockerized

.DEFAULT_GOAL := help

define uppercase
$(shell sed -r 's/(^|-)(\w)/\U\2/g' <<< $(1))
Expand Down Expand Up @@ -112,9 +123,68 @@ check-event-features:
fmt:
cargo +nightly fmt --all

build-examples:
HANDLERS_TO_BUILD=${HANDLERS_TO_BUILD} OUTPUT_DIR=${OUTPUT_DIR} ./scripts/build-examples.sh

nuke:
docker kill $$(docker ps -q)

test-dockerized: build-examples
@echo "Running dockerized tests locally..."

@echo "Building base Docker image with RIE and custom entrypoint..."
docker build \
-t local/test-base \
-f Dockerfile.test \
.

@echo "Setting up containerized test runner..."
@if [ ! -d ".test-runner" ]; then \
echo "Cloning containerized-test-runner-for-aws-lambda..."; \
git clone --quiet https://github.com/aws/containerized-test-runner-for-aws-lambda.git .test-runner; \
fi
@echo "Building test runner Docker image..."
@docker build -t test-runner:local -f .test-runner/Dockerfile .test-runner

@echo "Running tests in Docker..."
@docker run --rm \
-e INPUT_SUITE_FILE_ARRAY='["./test/dockerized/suites/*.json"]' \
-e DOCKER_IMAGE_NAME=local/test-base \
-e TASK_FOLDER=./test/dockerized/tasks \
-e GITHUB_WORKSPACE=/workspace \
-v /var/run/docker.sock:/var/run/docker.sock \
-v "$(CURDIR):/workspace" \
-w /workspace \
test-runner:local

test-rie:
./scripts/test-rie.sh $(EXAMPLE)
HANDLER="$(HANDLER)" ./scripts/test-rie.sh

# Run RIE in Lambda Managed Instance (LMI) mode with concurrent polling.
test-rie-lmi:
RIE_MAX_CONCURRENCY=$(RIE_MAX_CONCURRENCY) ./scripts/test-rie.sh $(EXAMPLE)
RIE_MAX_CONCURRENCY=$(RIE_MAX_CONCURRENCY) HANDLER="$(HANDLER)" ./scripts/test-rie.sh $(EXAMPLE)

help: ## Show this help message
@echo 'Usage: make [target]'
@echo ''
@echo 'Available targets:'
@echo ' pr-check Run pre-commit checks (fmt, clippy, tests)'
@echo ' integration-tests Build and run AWS integration tests'
@echo ' check-event-features Test individual event features'
@echo ' fmt Format code with cargo fmt'
@echo ' build-examples Build example Lambda functions'
@echo ' Usage: EXAMPLES="basic-lambda" OUTPUT_DIR=/make build-examples'
@echo ' test-rie Test Lambda with Runtime Interface Emulator'
@echo ' Usage: HANDLERS_TO_BUILD="basic-lambda basic-sqs" make test-rie'
@echo ' Usage: HANDLERS_TO_BUILD="basic-lambda" HANDLER="basic-lambda" make test-rie'
@echo ' test-rie-lmi Test RIE in Lambda Managed Instance mode'
@echo ' Usage: RIE_MAX_CONCURRENCY=4 HANDLERS_TO_BUILD="basic-lambda-concurrent" make test-rie-lmi'
@echo ' test-dockerized Run dockerized test harness'
@echo ' nuke Kill all running Docker containers'
@echo ''
@echo 'Environment variables:'
@echo ' EXAMPLES Space-separated list of examples to build (for build-examples)'
@echo ' HANDLERS_TO_BUILD Space-separated list of handlers to build for RIE (for test-rie)'
@echo ' HANDLER Specific handler to run (defaults to first in HANDLERS_TO_BUILD)'
@echo ' OUTPUT_DIR Directory for built binaries (default: /tmp/var-task for build-examples, /var/task for Docker)'
@echo ' RIE_MAX_CONCURRENCY Max concurrent Lambda invocations for LMI mode (for test-rie-lmi)'
52 changes: 39 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -392,34 +392,60 @@ You can read more about how [cargo lambda watch](https://www.cargo-lambda.info/c

### Local testing with Runtime Interface Emulator (RIE)

For testing with the official AWS Lambda Runtime Interface Emulator, use the provided RIE testing infrastructure:
For testing with the official AWS Lambda Runtime Interface Emulator:

```bash
make test-rie
```

By default, this uses the `basic-lambda` example. To test a different example:
By default, this builds and tests the `basic-lambda` example. To build and test a custom handler:

```bash
make test-rie EXAMPLE=basic-sqs
make test-rie EXAMPLE=http-basic-lambda
HANDLER="basic-tenant-id" make test-rie
```

To test Lambda Managed Instances (concurrent polling), use:
To test Lambda Managed Instances (concurrent polling):

```bash
make test-rie-lmi EXAMPLE=basic-lambda-concurrent
RIE_MAX_CONCURRENCY=4 make test-rie
```

This command will:
1. Build a Docker image with Rust toolchain and RIE
2. Compile the specified example inside the Linux container
3. Start the RIE container on port 9000
4. Display the appropriate curl command for testing

Different examples expect different payload formats. Check the example's source code in `examples/EXAMPLE_NAME/src/main.rs`

This provides automated testing with Docker and RIE, ensuring your Lambda functions work in a Linux environment identical to AWS Lambda.
### Dockerized test harness

For automated testing with AWS's containerized test runner:

```bash
make test-dockerized
```

This runs test suites defined in `test/dockerized/*.json` files using the [containerized-test-runner-for-aws-lambda](https://github.com/aws/containerized-test-runner-for-aws-lambda). Test suites specify handlers to test (from examples), request payloads, and expected response assertions.

Example test suite (`test/dockerized/core.json`):
```json
{
"tests": [
{
"name": "test_echo",
"handler": "basic-lambda",
"request": {
"command": "test"
},
"assertions": [
{
"response": {
"msg": "Command test executed."
},
"transform": "{msg: .msg}"
}
]
}
]
}
```

The `transform` field uses jq syntax to extract specific fields from responses before comparison, useful when responses include dynamic fields like request IDs.

### Lambda Debug Proxy

Expand Down
23 changes: 23 additions & 0 deletions scripts/build-examples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
set -e

OUTPUT_DIR="${OUTPUT_DIR:-/tmp/var-task}"
HANDLERS_TO_BUILD="${HANDLERS_TO_BUILD:-}"

mkdir -p "$OUTPUT_DIR"

echo "Building handlers: ${HANDLERS_TO_BUILD}"


for handler in ${HANDLERS_TO_BUILD}; do
dir="examples/$handler"
[ ! -f "$dir/Cargo.toml" ] && echo "$handler not found" && continue

echo "Building $handler..."
(cd "$dir" && cargo build --release) || continue

[ -f "$dir/target/release/$handler" ] && cp "$dir/target/release/$handler" "$OUTPUT_DIR/" && echo "$handler"
done

echo ""
ls -lh "$OUTPUT_DIR/" 2>/dev/null || echo "No binaries built"
15 changes: 15 additions & 0 deletions scripts/custom-lambda-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
# custom entrypoint script to allow selection of multiple rust binaries for dockerized tests
set -e

HANDLER=${1:-basic-lambda}

if [ -f "/var/task/$HANDLER" ]; then
ln -sf "/var/task/$HANDLER" "${LAMBDA_RUNTIME_DIR}/bootstrap"
exec /usr/local/bin/aws-lambda-rie "${LAMBDA_RUNTIME_DIR}/bootstrap"
else
echo "Error: Handler '$HANDLER' not found in /var/task"
echo "Available handlers:"
ls -la /var/task
exit 1
fi
2 changes: 1 addition & 1 deletion scripts/test-rie.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ fi
echo ""
echo "Press Ctrl+C to stop the container."

wait $CONTAINER_PID
wait $CONTAINER_PID
19 changes: 19 additions & 0 deletions test/dockerized/suites/core.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"tests": [
{
"name": "test_echo",
"handler": "basic-lambda",
"request": {
"command": "test"
},
"assertions": [
{
"response": {
"msg": "Command test executed."
},
"transform": "{msg: .msg}"
}
]
}
]
}