Skip to content

Commit 7820afe

Browse files
author
AntoniaSzecsi
committed
Solve PR comments
1 parent af2f2ce commit 7820afe

File tree

9 files changed

+88
-67
lines changed

9 files changed

+88
-67
lines changed

.dockerignore

Lines changed: 0 additions & 9 deletions
This file was deleted.

.github/workflows/test-rie.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Test with RIE
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
push:
7+
branches: [ main ]
8+
9+
jobs:
10+
test-rie:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
example: [basic-lambda, basic-sqs]
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Build and test ${{ matrix.example }} with RIE
20+
run: |
21+
docker build -f Dockerfile.rie --build-arg EXAMPLE=${{ matrix.example }} -t rust-lambda-rie-test-${{ matrix.example }} .
22+
23+
# Start container in background
24+
docker run -d -p 9000:8080 --name rie-test-${{ matrix.example }} rust-lambda-rie-test-${{ matrix.example }}
25+
26+
# Wait for container to be ready
27+
sleep 5
28+
29+
# Test the function based on example type
30+
if [ "${{ matrix.example }}" = "basic-lambda" ]; then
31+
PAYLOAD='{"command": "test from CI"}'
32+
elif [ "${{ matrix.example }}" = "basic-sqs" ]; then
33+
PAYLOAD='{"Records": [{"body": "{\"id\": \"123\", \"text\": \"hello from SQS\"}", "messageId": "test-id", "receiptHandle": "test-handle", "attributes": {}, "messageAttributes": {}, "md5OfBody": "test-md5", "eventSource": "aws:sqs", "eventSourceARN": "arn:aws:sqs:us-east-1:123456789012:test-queue", "awsRegion": "us-east-1"}]}'
34+
fi
35+
36+
# Make request and verify response
37+
RESPONSE=$(curl -s -XPOST 'http://localhost:9000/2015-03-31/functions/function/invocations' \
38+
-d "$PAYLOAD" \
39+
-H 'Content-Type: application/json')
40+
41+
echo "Response: $RESPONSE"
42+
43+
# Basic validation that we got a response (not empty)
44+
if [ -z "$RESPONSE" ]; then
45+
echo "Error: Empty response"
46+
exit 1
47+
fi
48+
49+
# Stop container
50+
docker stop rie-test-${{ matrix.example }}

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ members = [
99
"lambda-events",
1010
]
1111

12-
exclude = ["examples", "test-handler"]
12+
exclude = ["examples"]
1313

1414
[workspace.dependencies]
1515
base64 = "0.22"

Dockerfile.rie

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,19 @@ ENV PATH="/root/.cargo/bin:${PATH}"
77
ADD https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie /usr/local/bin/aws-lambda-rie
88
RUN chmod +x /usr/local/bin/aws-lambda-rie
99

10-
COPY . /build
11-
WORKDIR /build/test-handler
10+
ARG EXAMPLE=basic-lambda
11+
12+
COPY Cargo.toml Cargo.lock /build/
13+
COPY lambda-runtime /build/lambda-runtime
14+
COPY lambda-runtime-api-client /build/lambda-runtime-api-client
15+
COPY lambda-events /build/lambda-events
16+
COPY lambda-http /build/lambda-http
17+
COPY lambda-extension /build/lambda-extension
18+
COPY examples/${EXAMPLE} /build/examples/${EXAMPLE}
19+
20+
WORKDIR /build/examples/${EXAMPLE}
1221
RUN cargo build --release
13-
RUN cp target/release/test-handler ${LAMBDA_RUNTIME_DIR}/bootstrap
22+
RUN cp target/release/${EXAMPLE} ${LAMBDA_RUNTIME_DIR}/bootstrap
1423

1524
ENTRYPOINT []
1625
CMD [ "/usr/local/bin/aws-lambda-rie", "/var/runtime/bootstrap" ]

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,4 @@ fmt:
111111
cargo +nightly fmt --all
112112

113113
test-rie:
114-
./scripts/test-rie.sh
114+
./scripts/test-rie.sh $(EXAMPLE)

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -400,19 +400,20 @@ For testing with the official AWS Lambda Runtime Interface Emulator, use the pro
400400
make test-rie
401401
```
402402

403+
By default, this uses the `basic-lambda` example. To test a different example:
404+
405+
```bash
406+
make test-rie EXAMPLE=basic-sqs
407+
make test-rie EXAMPLE=http-basic-lambda
408+
```
409+
403410
This command will:
404411
1. Build a Docker image with Rust toolchain and RIE
405-
2. Compile the test handler inside the Linux container
412+
2. Compile the specified example inside the Linux container
406413
3. Start the RIE container on port 9000
407-
4. Display the curl command to test your function
414+
4. Display the appropriate curl command for testing
408415

409-
Once running, test the function from another terminal:
410-
411-
```bash
412-
curl -XPOST 'http://localhost:9000/2015-03-31/functions/function/invocations' \
413-
-d '{"command": "test from RIE"}' \
414-
-H 'Content-Type: application/json'
415-
```
416+
Different examples expect different payload formats. Check the example's source code in `examples/EXAMPLE_NAME/src/main.rs`
416417

417418
This provides automated testing with Docker and RIE, ensuring your Lambda functions work in a Linux environment identical to AWS Lambda.
418419

scripts/test-rie.sh

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
#!/bin/bash
22
set -euo pipefail
33

4-
echo "Building Docker image with RIE..."
5-
docker build -f Dockerfile.rie -t rust-lambda-rie-test .
4+
EXAMPLE=${1:-basic-lambda}
5+
6+
echo "Building Docker image with RIE for example: $EXAMPLE..."
7+
docker build -f Dockerfile.rie --build-arg EXAMPLE=$EXAMPLE -t rust-lambda-rie-test .
68

79
echo "Starting RIE container on port 9000..."
8-
docker run -p 9000:8080 rust-lambda-rie-test
10+
docker run -p 9000:8080 rust-lambda-rie-test &
11+
CONTAINER_PID=$!
912

1013
echo "Container started. Test with:"
11-
echo "curl -XPOST 'http://localhost:9000/2015-03-31/functions/function/invocations' -d '{\"command\": \"test from RIE\"}' -H 'Content-Type: application/json'"
14+
if [ "$EXAMPLE" = "basic-lambda" ]; then
15+
echo "curl -XPOST 'http://localhost:9000/2015-03-31/functions/function/invocations' -d '{\"command\": \"test from RIE\"}' -H 'Content-Type: application/json'"
16+
else
17+
echo "For example '$EXAMPLE', check examples/$EXAMPLE/src/main.rs for the expected payload format."
18+
fi
1219
echo ""
13-
echo "Press Ctrl+C to stop the container."
20+
echo "Press Ctrl+C to stop the container."
21+
22+
wait $CONTAINER_PID

test-handler/Cargo.toml

Lines changed: 0 additions & 9 deletions
This file was deleted.

test-handler/src/main.rs

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)