Skip to content

Commit 72f658e

Browse files
committed
refactor: ♻️ some small fixes
1 parent 8ce868b commit 72f658e

6 files changed

Lines changed: 60 additions & 42 deletions

File tree

Dockerfile.rie

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ FROM public.ecr.aws/lambda/provided:al2023 AS builder
33
RUN dnf install -y gcc make
44
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
55
ENV PATH="/root/.cargo/bin:${PATH}"
6-
ENV EXAMPLES="basic-lambda"
7-
ENV OUTPUT_DIR="/var/task"
6+
7+
ARG HANDLERS_TO_BUILD="basic-lambda"
8+
ARG OUTPUT_DIR="/var/task"
89

910
COPY Cargo.* /build/
1011
COPY lambda-runtime /build/lambda-runtime
@@ -16,7 +17,7 @@ COPY examples /build/examples
1617
COPY scripts/build-examples.sh /build/
1718

1819
WORKDIR /build
19-
RUN chmod +x build-examples.sh && ./build-examples.sh
20+
RUN chmod +x build-examples.sh && HANDLERS_TO_BUILD="$HANDLERS_TO_BUILD" OUTPUT_DIR="$OUTPUT_DIR" ./build-examples.sh
2021

2122
# Final Image
2223
FROM public.ecr.aws/lambda/provided:al2023

Makefile

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ INTEG_EXTENSIONS := extension-fn extension-trait logs-trait
77
INTEG_ARCH := x86_64-unknown-linux-musl
88
RIE_MAX_CONCURRENCY ?= 4
99
OUTPUT_DIR ?= /tmp/var-task
10-
EXAMPLES ?=
10+
HANDLERS_TO_BUILD ?= basic-lambda
11+
HANDLER ?= basic-lambda
1112

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

@@ -119,7 +120,10 @@ fmt:
119120
cargo +nightly fmt --all
120121

121122
build-examples:
122-
./scripts/build-examples.sh
123+
HANDLERS_TO_BUILD=${HANDLERS_TO_BUILD} ./scripts/build-examples.sh
124+
125+
nuke:
126+
docker kill $$(docker ps -q)
123127

124128
test-dockerized:
125129
@echo "Running dockerized tests locally..."
@@ -144,14 +148,11 @@ test-dockerized:
144148
/tests/*.json
145149

146150
test-rie:
147-
./scripts/test-rie.sh
148-
149-
nuke:
150-
docker kill $$(docker ps -q)
151+
HANDLER="$(HANDLER)" ./scripts/test-rie.sh
151152

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

156157
help: ## Show this help message
157158
@echo 'Usage: make [target]'
@@ -162,14 +163,18 @@ help: ## Show this help message
162163
@echo ' check-event-features Test individual event features'
163164
@echo ' fmt Format code with cargo fmt'
164165
@echo ' build-examples Build example Lambda functions'
165-
@echo ' Usage: EXAMPLES="basic-lambda" make build-examples'
166+
@echo ' Usage: EXAMPLES="basic-lambda" OUTPUT_DIR=/make build-examples'
166167
@echo ' test-rie Test Lambda with Runtime Interface Emulator'
168+
@echo ' Usage: HANDLERS_TO_BUILD="basic-lambda basic-sqs" make test-rie'
169+
@echo ' Usage: HANDLERS_TO_BUILD="basic-lambda" HANDLER="basic-lambda" make test-rie'
167170
@echo ' test-rie-lmi Test RIE in Lambda Managed Instance mode'
168-
@echo ' Usage: RIE_MAX_CONCURRENCY=4 make test-rie-lmi'
171+
@echo ' Usage: RIE_MAX_CONCURRENCY=4 HANDLERS_TO_BUILD="basic-lambda-concurrent" make test-rie-lmi'
169172
@echo ' test-dockerized Run dockerized test harness'
170173
@echo ' nuke Kill all running Docker containers'
171174
@echo ''
172175
@echo 'Environment variables:'
173-
@echo ' EXAMPLES Space-separated list of examples to build'
174-
@echo ' OUTPUT_DIR Directory for built binaries (default: /tmp/var-task)'
175-
@echo ' RIE_MAX_CONCURRENCY Max concurrent Lambda invocations for LMI mode'
176+
@echo ' EXAMPLES Space-separated list of examples to build (for build-examples)'
177+
@echo ' HANDLERS_TO_BUILD Space-separated list of handlers to build for RIE (for test-rie)'
178+
@echo ' HANDLER Specific handler to run (defaults to first in HANDLERS_TO_BUILD)'
179+
@echo ' OUTPUT_DIR Directory for built binaries (default: /tmp/var-task for build-examples, /var/task for Docker)'
180+
@echo ' RIE_MAX_CONCURRENCY Max concurrent Lambda invocations for LMI mode (for test-rie-lmi)'

README.md

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -392,35 +392,26 @@ You can read more about how [cargo lambda watch](https://www.cargo-lambda.info/c
392392

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

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

397397
```bash
398398
make test-rie
399399
```
400400

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

403403
```bash
404-
make test-rie EXAMPLE=basic-sqs
405-
make test-rie EXAMPLE=http-basic-lambda
404+
HANDLER="basic-tenant-id" make test-rie
406405
```
407406

408-
To test Lambda Managed Instances (concurrent polling), use:
407+
To test Lambda Managed Instances (concurrent polling):
409408

410409
```bash
411-
make test-rie-lmi EXAMPLE=basic-lambda-concurrent
410+
RIE_MAX_CONCURRENCY=4 make test-rie
412411
```
413412

414-
This command will:
415-
1. Build a Docker image with Rust toolchain and RIE
416-
2. Compile the specified example inside the Linux container
417-
3. Start the RIE container on port 9000
418-
4. Display the appropriate curl command for testing
419-
420413
Different examples expect different payload formats. Check the example's source code in `examples/EXAMPLE_NAME/src/main.rs`
421414

422-
This provides automated testing with Docker and RIE, ensuring your Lambda functions work in a Linux environment identical to AWS Lambda.
423-
424415
### Lambda Debug Proxy
425416

426417
Lambdas can be run and debugged locally using a special [Lambda debug proxy](https://github.com/rimutaka/lambda-debug-proxy) (a non-AWS repo maintained by @rimutaka), which is a Lambda function that forwards incoming requests to one AWS SQS queue and reads responses from another queue. A local proxy running on your development computer reads the queue, calls your Lambda locally and sends back the response. This approach allows debugging of Lambda functions locally while being part of your AWS workflow. The Lambda handler code does not need to be modified between the local and AWS versions.

scripts/build-examples.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
set -e
33

44
OUTPUT_DIR="${OUTPUT_DIR:-/tmp/var-task}"
5-
EXAMPLES="${EXAMPLES:-}"
5+
HANDLERS_TO_BUILD="${HANDLERS_TO_BUILD:-}"
66

77
mkdir -p "$OUTPUT_DIR"
88

9-
echo "Building examples: $(EXAMPLES)"
9+
echo "Building handlers: ${HANDLERS_TO_BUILD}"
1010

1111

12-
for example in ${EXAMPLES}; do
13-
dir="examples/$example"
14-
[ ! -f "$dir/Cargo.toml" ] && echo "$example not found" && continue
12+
for handler in ${HANDLERS_TO_BUILD}; do
13+
dir="examples/$handler"
14+
[ ! -f "$dir/Cargo.toml" ] && echo "$handler not found" && continue
1515

16-
echo "Building $example..."
16+
echo "Building $handler..."
1717
(cd "$dir" && cargo build --release) || continue
1818

19-
[ -f "$dir/target/release/$example" ] && cp "$dir/target/release/$example" "$OUTPUT_DIR/" && echo "$example"
19+
[ -f "$dir/target/release/$handler" ] && cp "$dir/target/release/$handler" "$OUTPUT_DIR/" && echo "$handler"
2020
done
2121

2222
echo ""

scripts/test-rie.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,24 @@ set -euo pipefail
33

44
# Optional: set RIE_MAX_CONCURRENCY to enable LMI mode (emulates AWS_LAMBDA_MAX_CONCURRENCY)
55
RIE_MAX_CONCURRENCY=${RIE_MAX_CONCURRENCY:-}
6+
# Optional: specify which handler to run (defaults to first handler)
7+
HANDLER=${HANDLER:-basic-lambda}
68

7-
echo "Building Docker image with RIE"
8-
docker build -f Dockerfile.rie -t rust-lambda-rie-test .
9+
echo "Building Docker image with RIE (handlers: $HANDLER)"
10+
docker build -f Dockerfile.rie --build-arg HANDLERS_TO_BUILD="$HANDLER" -t rust-lambda-rie-test .
911

10-
echo "Starting RIE container on port 9000..."
12+
echo "Starting RIE container on port 9000 with handler: $HANDLER"
1113
if [ -n "$RIE_MAX_CONCURRENCY" ]; then
1214
echo "Enabling LMI mode with AWS_LAMBDA_MAX_CONCURRENCY=$RIE_MAX_CONCURRENCY"
13-
docker run -p 9000:8080 -e AWS_LAMBDA_MAX_CONCURRENCY="$RIE_MAX_CONCURRENCY" rust-lambda-rie-test &
15+
docker run -p 9000:8080 -e AWS_LAMBDA_MAX_CONCURRENCY="$RIE_MAX_CONCURRENCY" rust-lambda-rie-test "$HANDLER" &
1416
else
15-
docker run -p 9000:8080 rust-lambda-rie-test &
17+
docker run -p 9000:8080 rust-lambda-rie-test "$HANDLER" &
1618
fi
1719
CONTAINER_PID=$!
1820

1921
echo "Container started. Test with:"
2022
echo "curl -XPOST 'http://localhost:9000/2015-03-31/functions/function/invocations' -d '{\"command\": \"test from RIE\"}' -H 'Content-Type: application/json'"
21-
echo "or for a specific example check under examples/ for the expected payload format."
23+
echo "or for a specific example check under examples/ for the expected payload format."
2224

2325
echo ""
2426
echo "Press Ctrl+C to stop the container."

tests/dockerized/core.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"tests": [
3+
{
4+
"name": "test_echo",
5+
"handler": "basic-lambda",
6+
"request": {
7+
"command": "test"
8+
},
9+
"assertions": [
10+
{
11+
"response": {
12+
"msg": "Command test executed."
13+
},
14+
"transform": "{msg: .msg}"
15+
}
16+
]
17+
}
18+
]
19+
}

0 commit comments

Comments
 (0)