-
Notifications
You must be signed in to change notification settings - Fork 371
Add local testing infrastructure with AWS Lambda Runtime Interface Emulator (RIE) #1033
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
name: Test with RIE | ||
|
||
on: | ||
pull_request: | ||
branches: [ main ] | ||
push: | ||
branches: [ main ] | ||
|
||
jobs: | ||
test-rie: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
example: [basic-lambda, basic-sqs] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Build and test ${{ matrix.example }} with RIE | ||
run: | | ||
docker build -f Dockerfile.rie --build-arg EXAMPLE=${{ matrix.example }} -t rust-lambda-rie-test-${{ matrix.example }} . | ||
|
||
# Start container in background | ||
docker run -d -p 9000:8080 --name rie-test-${{ matrix.example }} rust-lambda-rie-test-${{ matrix.example }} | ||
|
||
# Wait for container to be ready | ||
sleep 5 | ||
|
||
# Test the function based on example type | ||
if [ "${{ matrix.example }}" = "basic-lambda" ]; then | ||
PAYLOAD='{"command": "test from CI"}' | ||
elif [ "${{ matrix.example }}" = "basic-sqs" ]; then | ||
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"}]}' | ||
fi | ||
|
||
# Make request and verify response | ||
RESPONSE=$(curl -s -XPOST 'http://localhost:9000/2015-03-31/functions/function/invocations' \ | ||
-d "$PAYLOAD" \ | ||
-H 'Content-Type: application/json') | ||
|
||
echo "Response: $RESPONSE" | ||
|
||
# Basic validation that we got a response (not empty) | ||
if [ -z "$RESPONSE" ]; then | ||
echo "Error: Empty response" | ||
exit 1 | ||
fi | ||
|
||
# Stop container | ||
docker stop rie-test-${{ matrix.example }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
FROM public.ecr.aws/lambda/provided:al2023 | ||
|
||
RUN dnf install -y gcc | ||
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y | ||
ENV PATH="/root/.cargo/bin:${PATH}" | ||
|
||
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 | ||
|
||
ARG EXAMPLE=basic-lambda | ||
|
||
COPY Cargo.toml Cargo.lock /build/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is causing CI failures since we don't currently have
https://github.com/awslabs/aws-lambda-rust-runtime/actions/runs/17301603573/job/49114895249?pr=1033 Maybe just do Certainly you could update CI to use cargo-generate-lockfile but that seems kind of annoying. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for this! ☑️ |
||
COPY lambda-runtime /build/lambda-runtime | ||
COPY lambda-runtime-api-client /build/lambda-runtime-api-client | ||
COPY lambda-events /build/lambda-events | ||
COPY lambda-http /build/lambda-http | ||
COPY lambda-extension /build/lambda-extension | ||
COPY examples/${EXAMPLE} /build/examples/${EXAMPLE} | ||
|
||
WORKDIR /build/examples/${EXAMPLE} | ||
RUN cargo build --release | ||
RUN cp target/release/${EXAMPLE} ${LAMBDA_RUNTIME_DIR}/bootstrap | ||
|
||
ENTRYPOINT [] | ||
CMD [ "/usr/local/bin/aws-lambda-rie", "/var/runtime/bootstrap" ] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
EXAMPLE=${1:-basic-lambda} | ||
|
||
echo "Building Docker image with RIE for example: $EXAMPLE..." | ||
docker build -f Dockerfile.rie --build-arg EXAMPLE=$EXAMPLE -t rust-lambda-rie-test . | ||
|
||
echo "Starting RIE container on port 9000..." | ||
docker run -p 9000:8080 rust-lambda-rie-test & | ||
CONTAINER_PID=$! | ||
|
||
echo "Container started. Test with:" | ||
if [ "$EXAMPLE" = "basic-lambda" ]; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good middle ground for making it turnkey, thanks. |
||
echo "curl -XPOST 'http://localhost:9000/2015-03-31/functions/function/invocations' -d '{\"command\": \"test from RIE\"}' -H 'Content-Type: application/json'" | ||
else | ||
echo "For example '$EXAMPLE', check examples/$EXAMPLE/src/main.rs for the expected payload format." | ||
fi | ||
echo "" | ||
echo "Press Ctrl+C to stop the container." | ||
|
||
wait $CONTAINER_PID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!