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 the keys in the following table when called through a REST API as part of an API Gateway trigger:

    Table 1. Hash Keys for Event
    Key Associated Value

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


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


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


    A hash with the request headers.


    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

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.