diff --git a/README.md b/README.md index ac5a9c1..2ff43af 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,16 @@ ## AWS Lambda Ruby Runtime Interface Client -We have open-sourced a set of software packages, Runtime Interface Clients (RIC), that implement the Lambda - [Runtime API](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-api.html), allowing you to seamlessly extend your preferred - base images to be Lambda compatible. -The Lambda Runtime Interface Client is a lightweight interface that allows your runtime to receive requests from and send requests to the Lambda service. +We have open-sourced a set of software packages, Runtime Interface Clients (RIC), that implements the Lambda +[Runtime API](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-api.html), allowing you to seamlessly extend +your preferred base images to be Lambda compatible. +The Lambda Runtime Interface Client is a lightweight interface that allows your runtime to +receive requests from and send requests to the Lambda service. The Lambda Ruby Runtime Interface Client is vended through [rubygems](https://rubygems.org/gems/aws_lambda_ric). You can include this package in your preferred base image to make that base image Lambda compatible. ## Requirements -The Ruby Runtime Interface Client package currently supports Ruby versions: - - 3.2 and 3.3 +The Ruby Runtime Interface Client package currently supports ruby 3.0 and above. ## Usage @@ -37,17 +37,9 @@ Or install it manually as: $ gem install aws_lambda_ric - -Next step would be to copy your Lambda function code into the image's working directory. -```dockerfile -# Copy function code -RUN mkdir -p ${FUNCTION_DIR} -COPY app.rb ${FUNCTION_DIR} - -WORKDIR ${FUNCTION_DIR} -``` - -The next step would be to set the `ENTRYPOINT` property of the Docker image to invoke the Runtime Interface Client and then set the `CMD` argument to specify the desired handler. +The next step would be to copy your Lambda function code into the image's working directory. +You will need to set the `ENTRYPOINT` property of the Docker image to invoke the Runtime Interface Client and +then set the `CMD` argument to specify the desired handler. Example Dockerfile: ```dockerfile @@ -84,7 +76,18 @@ ENTRYPOINT ["/usr/local/bin/aws_lambda_ric"] CMD ["app.App::Handler.process"] ``` -Example Ruby handler `app.rb`: +Note that the `ENTRYPOINT` may differ based on the base image used. You can find the correct path by running an +interactive shell in the container and checking the installed location of the gem. + +```shell script +docker run -it --rm amazonlinux:latest bash +yum install -y which ruby +gem install aws_lambda_ric +which aws_lambda_ric +``` + +Finally, create a Ruby handler. This is an example `app.rb`: + ```ruby module App class Handler @@ -97,7 +100,10 @@ end ### Local Testing -To make it easy to locally test Lambda functions packaged as container images we open-sourced a lightweight web-server, Lambda Runtime Interface Emulator (RIE), which allows your function packaged as a container image to accept HTTP requests. You can install the [AWS Lambda Runtime Interface Emulator](https://github.com/aws/aws-lambda-runtime-interface-emulator) on your local machine to test your function. Then when you run the image function, you set the entrypoint to be the emulator. +To make it easy to locally test Lambda functions packaged as container images we open-sourced a lightweight web-server, +Lambda Runtime Interface Emulator (RIE), which allows your function packaged as a container image to accept HTTP requests. +You can install the [AWS Lambda Runtime Interface Emulator](https://github.com/aws/aws-lambda-runtime-interface-emulator) on your local machine to test your function. +Thenm when you run the image function, you set the entrypoint to be the emulator. *To install the emulator and test your Lambda function* @@ -108,7 +114,8 @@ mkdir -p ~/.aws-lambda-rie && \ curl -Lo ~/.aws-lambda-rie/aws-lambda-rie https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie && \ chmod +x ~/.aws-lambda-rie/aws-lambda-rie ``` -2) Run your Lambda image function using the docker run command. + +1) Run your Lambda image function using the docker run command. ```shell script docker run -d -v ~/.aws-lambda-rie:/aws-lambda -p 9000:8080 \ @@ -119,7 +126,7 @@ docker run -d -v ~/.aws-lambda-rie:/aws-lambda -p 9000:8080 \ This runs the image as a container and starts up an endpoint locally at `http://localhost:9000/2015-03-31/functions/function/invocations`. -3) Post an event to the following endpoint using a curl command: +1) Post an event to the following endpoint using a curl command: ```shell script curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}'