Skip to content

Update README for ENTRYPOINT #41

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
merged 1 commit into from
Mar 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 28 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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*

Expand All @@ -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 \
Expand All @@ -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 '{}'
Expand Down