diff --git a/Dockerfile.rie b/Dockerfile.rie new file mode 100644 index 0000000..021150f --- /dev/null +++ b/Dockerfile.rie @@ -0,0 +1,19 @@ +FROM public.ecr.aws/lambda/ruby:3.3 + +# 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 && \ + 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..3efa2bb 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,10 @@ test-integ: setup-codebuild-agent build: rake build +.PHONY: run-local-ric +run-local-ric: + scripts/run-local-ric.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. + 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 2ff43af..1a682bb 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 run your local RIC changes, use the one-command setup: + +```shell script +make run-local-ric +``` + +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/run-local-ric.sh b/scripts/run-local-ric.sh new file mode 100755 index 0000000..78a6e10 --- /dev/null +++ b/scripts/run-local-ric.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