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, 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. 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:
- 2.5.x up to and including 2.7.x
Usage
Creating a Docker Image for Lambda with the Runtime Interface Client
First step is to choose the base image to be used. The supported Linux OS distributions are:
- Amazon Linux 2
- Alpine
- CentOS
- Debian
- Ubuntu
In order to install the Runtime Interface Client, either add this line to your application's Gemfile:
gem 'aws_lambda_ric'
And then execute:
$ bundle
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.
# Create function directory
RUN mkdir -p ${FUNCTION_DIR}
# Copy handler function
COPY app.rb ${FUNCTION_DIR}/app.rb
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.
Example Dockerfile:
FROM amazonlinux:latest
# Define custom function directory
ARG FUNCTION_DIR="/function"
# Install ruby
RUN amazon-linux-extras install -y ruby2.6
# Install the Runtime Interface Client
RUN gem install aws_lambda_ric
# Create function directory
RUN mkdir -p ${FUNCTION_DIR}
# Copy handler function
COPY app.rb ${FUNCTION_DIR}/app.rb
WORKDIR ${FUNCTION_DIR}
ENTRYPOINT ["aws_lambda_ric"]
CMD ["app.App::Handler.process"]
Example Ruby handler app.rb:
module App
class Handler
def self.process(event:, context:)
message = "Hello World!"
{ statusCode: 200, body: { 'message': message } }
end
end
end
Local Testing
For testing locally you will need to set up a local Runtime Interface Emulator against which the Runtime Interface Client will make API calls. You will need to post data to the endpoint it creates in order to invoke your function. For more information check out the Runtime Interface Emulator.
Security
If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our vulnerability reporting page. Please do not create a public github issue.
License
This project is licensed under the Apache-2.0 License.