From dcd903a83ea6e6d10784aef742d7c5987cd40165 Mon Sep 17 00:00:00 2001 From: AntoniaSzecsi Date: Thu, 4 Sep 2025 12:01:35 +0100 Subject: [PATCH 1/4] Implement automated local testing with RIE --- Dockerfile.rie | 16 +++++++++++ Makefile | 5 ++++ README.md | 22 ++++++++++++++ scripts/test-rie.sh | 22 ++++++++++++++ test/integration/docker-compose.template.yml | 30 -------------------- 5 files changed, 65 insertions(+), 30 deletions(-) create mode 100644 Dockerfile.rie create mode 100755 scripts/test-rie.sh delete mode 100644 test/integration/docker-compose.template.yml diff --git a/Dockerfile.rie b/Dockerfile.rie new file mode 100644 index 0000000..0f2d68b --- /dev/null +++ b/Dockerfile.rie @@ -0,0 +1,16 @@ +FROM public.ecr.aws/lambda/ruby:3.2 + +# Copy source code and build gem in container +COPY . ${LAMBDA_TASK_ROOT}/ +WORKDIR ${LAMBDA_TASK_ROOT} + +# Build and install the RIC gem +RUN gem install bundler && \ + bundle install && \ + rake build && \ + gem install pkg/aws_lambda_ric-*.gem + +# Copy handler to task root +COPY test/integration/test-handlers/echo/app.rb ${LAMBDA_TASK_ROOT}/ + +CMD ["app.App::Handler.process"] \ No newline at end of file diff --git a/Makefile b/Makefile index e1c94f3..eb14a99 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,10 @@ test-integ: setup-codebuild-agent build: rake build +.PHONY: test-rie +test-rie: + scripts/test-rie.sh + .PHONY: pr pr: init test-unit test-smoke @@ -42,6 +46,7 @@ TARGETS test-integ Run Integration tests. test-unit Run Unit Tests. test-smoke Run Sanity/Smoke tests. + test-rie Tests local RIC with Runtime Interface Emulator. pr Perform all checks before submitting a Pull Request. endef diff --git a/README.md b/README.md index 2ff43af..f0ca697 100644 --- a/README.md +++ b/README.md @@ -136,6 +136,28 @@ This command invokes the function running in the container image and returns a r *Alternately, you can also include RIE as a part of your base image. See the AWS documentation on how to [Build RIE into your base image](https://docs.aws.amazon.com/lambda/latest/dg/images-test.html#images-test-alternative).* +### Automated Local Testing + +For a simple approach to test your local RIC changes, use the one-command test setup: + +```shell script +make test-rie +``` + +This command will: +1. Build a Docker image with your local RIC code +2. Compile the gem inside the Linux container (avoiding OS compatibility issues) +3. Start the Lambda Runtime Interface Emulator on port 9000 +4. Run a test Lambda function using your RIC + +Once running, invoke the function from another terminal: + +```shell script +curl -X POST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}' +``` + +Modify the test handler in `test/integration/test-handlers/echo/app.rb` to test different scenarios. + ## Development ### Building the package diff --git a/scripts/test-rie.sh b/scripts/test-rie.sh new file mode 100755 index 0000000..78a6e10 --- /dev/null +++ b/scripts/test-rie.sh @@ -0,0 +1,22 @@ +#!/bin/bash +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" + + +IMAGE_TAG="ruby-ric-rie-test" +HANDLER="${1:-app.App::Handler.process}" + +echo "Starting RIE test setup for Ruby..." + +echo "Building test Docker image..." +docker build -t "$IMAGE_TAG" -f "$PROJECT_ROOT/Dockerfile.rie" "$PROJECT_ROOT" + +echo "Starting test container on port 9000..." +echo "" +echo "In another terminal, invoke with:" +echo "curl -s -X POST -H 'Content-Type: application/json' \"http://localhost:9000/2015-03-31/functions/function/invocations\" -d '{\"message\":\"test\"}'" +echo "" + +exec docker run -it -p 9000:8080 -e _HANDLER="$HANDLER" "$IMAGE_TAG" \ No newline at end of file diff --git a/test/integration/docker-compose.template.yml b/test/integration/docker-compose.template.yml deleted file mode 100644 index 6247ff2..0000000 --- a/test/integration/docker-compose.template.yml +++ /dev/null @@ -1,30 +0,0 @@ -version: '3.3' -services: - function: - build: - context: . - args: - RUNTIME_VERSION: "${runtime_version}" - DISTRO_VERSION: "${distro_version}" - dockerfile: ./docker/Dockerfile.echo.${DISTRO} - environment: - - AWS_LAMBDA_RUNTIME_API=runtime:9001 - - runtime: - build: - context: . - dockerfile: ../docker-helpers/Dockerfile.runtime - - invoker: - build: - context: . - dockerfile: ../docker-helpers/Dockerfile.aws-cli - entrypoint: [ - aws, lambda, invoke, - --endpoint, http://runtime:9001, - --no-sign-request, - --region, us-west-2, - --function-name, ignored, - --payload, '{ "name": "Lambda" }', - /dev/stdout - ] \ No newline at end of file From ed180560c0a8e05ecc19d177116797d075dc71f6 Mon Sep 17 00:00:00 2001 From: AntoniaSzecsi Date: Thu, 4 Sep 2025 15:47:28 +0100 Subject: [PATCH 2/4] Change target name to a suggestive one --- Makefile | 8 ++++---- README.md | 4 ++-- scripts/{test-rie.sh => run-local-ric.sh} | 0 3 files changed, 6 insertions(+), 6 deletions(-) rename scripts/{test-rie.sh => run-local-ric.sh} (100%) diff --git a/Makefile b/Makefile index eb14a99..3efa2bb 100644 --- a/Makefile +++ b/Makefile @@ -27,9 +27,9 @@ test-integ: setup-codebuild-agent build: rake build -.PHONY: test-rie -test-rie: - scripts/test-rie.sh +.PHONY: run-local-ric +run-local-ric: + scripts/run-local-ric.sh .PHONY: pr pr: init test-unit test-smoke @@ -46,7 +46,7 @@ TARGETS test-integ Run Integration tests. test-unit Run Unit Tests. test-smoke Run Sanity/Smoke tests. - test-rie Tests local RIC with Runtime Interface Emulator. + run-local-ric Run local RIC changes with Runtime Interface Emulator. pr Perform all checks before submitting a Pull Request. endef diff --git a/README.md b/README.md index f0ca697..1a682bb 100644 --- a/README.md +++ b/README.md @@ -138,10 +138,10 @@ This command invokes the function running in the container image and returns a r ### Automated Local Testing -For a simple approach to test your local RIC changes, use the one-command test setup: +For a simple approach to run your local RIC changes, use the one-command setup: ```shell script -make test-rie +make run-local-ric ``` This command will: diff --git a/scripts/test-rie.sh b/scripts/run-local-ric.sh similarity index 100% rename from scripts/test-rie.sh rename to scripts/run-local-ric.sh From 86472bd1d1f96d7a84a94f1c170912c4e5989ae7 Mon Sep 17 00:00:00 2001 From: AntoniaSzecsi Date: Thu, 4 Sep 2025 16:58:57 +0100 Subject: [PATCH 3/4] Upgrade to the latest base image and create clean start --- Dockerfile.rie | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Dockerfile.rie b/Dockerfile.rie index 0f2d68b..bf42c07 100644 --- a/Dockerfile.rie +++ b/Dockerfile.rie @@ -1,9 +1,12 @@ -FROM public.ecr.aws/lambda/ruby:3.2 +FROM public.ecr.aws/lambda/ruby:3.3.2025.08.26.15 # Copy source code and build gem in container COPY . ${LAMBDA_TASK_ROOT}/ WORKDIR ${LAMBDA_TASK_ROOT} +# Uninstall any existing RIC gem for a clean start +RUN gem uninstall -x aws_lambda_ric || true + # Build and install the RIC gem RUN gem install bundler && \ bundle install && \ From 7d3ab3dd05fe5e25cf32deb9699029c8c54a2db3 Mon Sep 17 00:00:00 2001 From: AntoniaSzecsi Date: Fri, 5 Sep 2025 09:51:09 +0100 Subject: [PATCH 4/4] Update to point to the latest version --- Dockerfile.rie | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile.rie b/Dockerfile.rie index bf42c07..021150f 100644 --- a/Dockerfile.rie +++ b/Dockerfile.rie @@ -1,4 +1,4 @@ -FROM public.ecr.aws/lambda/ruby:3.3.2025.08.26.15 +FROM public.ecr.aws/lambda/ruby:3.3 # Copy source code and build gem in container COPY . ${LAMBDA_TASK_ROOT}/