The automatically generated code for an AWS Lambda function using the Ruby 2.5 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)
end
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 keys in the following table:

    Table 1. Hash Keys for Event
    Key Associated Value
    'httpMethod'

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

    'path'

    A string with the request path (the name of the Lambda function starting with a slash).

    'queryStringParameters'

    A hash with the query string parameters, or nil if the request has no query string.

    'headers'

    A hash with the request headers.

    'body'

    A string with the request body, or nil if the request has no body.

  • 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
:statusCode

An integer number with the HTTP response status code.

:body

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

:headers

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