-
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
Merged
+126
−1
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.* /build/ | ||
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" ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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!