The automatically generated code for an AWS Lambda function using the Ruby 2.7 runtime looks like this:

File: lambda_function.rb (original version)
require 'json'

def lambda_handler(event:, context:) (1)
    # TODO implement
    { statusCode: 200, body: JSON.generate('Hello from Lambda!') } (2)
1 The lambda_handler function has two parameters:
  • event: This parameter is a hash that is used to pass in event data to the handler. It contains, among others, the information detailed in the following table:

    Table 1. Contents of Event
    Keys Associated Value

    A string with the current version of this event object. Should be '2.0' at the time of this writing.


    A hash with the query string parameters (only if it actually has any).


    A hash with all the headers from the request.


    A string with the request body (only if it actually has one).


    A string with the domain name of the server where the AWS Lambda function is hosted.


    A string with the request HTTP method (GET or POST, for example).


    A string with the request path (for example /some_resource).


    A string with the HTTP version used by the request (HTTP/1.1, for example).

  • context: This parameter provides runtime information to your handler. Its type is LambdaContext.

2 The handler should return a hash from which the HTTP response will be constructed.
Table 2. Hash Keys for HTTP Response
Key Description

An integer number with the HTTP response status code.


A string with the response body. Typically, the result of calling JSON.generate method to produce JSON output.


This is an optional key, but if provided it should refer to a hash with additional response headers.