Request and response payloads

Review the default request and response formats that Gloo Gateway uses for sending and receiving payloads from Lambda functions, and the transformations you can apply to the response payload structure.

Default formats: When a workload in your Gloo Gateway environment sends a request to your Lambda function, Gateway applies a default transformation to the payload. When the function returns the response, Gloo Gateway also expects specific fields in the response payload. When you use these default payload formats, your Lambda must be coded to accept and return the Gloo Gateway format. Note that the default request and response transformations require your ingress gateway to run Istio 1.15.1 or later.

Additional transformations: Apply additional Gloo transformation policies, which allow you to customize the request and respone payloads for Lambda as needed.

Default request and response payloads

Review the default request and response formats that Gloo Gateway uses for sending and receiving payloads from Lambda functions.

Request format

When you send a request to your Lambda function, Gloo Gateway transforms the HTTP request into the following default payload format. Your Lambda function must be coded to receive data in this format in the event object.

Payload field Type Description
headers JSON object Mapping from request header keys to the request header values. Only single-value headers are supported.
body String Body of the HTTP request.
httpMethod String Method of the HTTP request.
path String Path of the HTTP request, without the query string.
queryString String Query string component of the HTTP request.

The following GET request payload is an example of the event object that your Lambda function receives from Gloo Gateway:

{
  "headers": {
    ":authority": "k8s-gloosyst-gatewayp-510fe2ccc8-027151f46d71bbd5.elb.us-east-2.amazonaws.com",
    ":method": "GET",
    ":path": "/lambda",
    ":scheme": "https",
    "accept": "*/*",
    "user-agent": "curl/7.79.1",
    "x-forwarded-proto": "https",
    "x-request-id": "eb5517c6-0ffc-4df5-a274-998de0980024"
  },
  "httpMethod": "GET",
  "path": "/lambda",
  "queryString": "foo=baz&baz=foo"
}

Response format

When your Lambda function returns a response, Gloo Gateway expects the following payload format. The response is unwrapped as if the gateway proxy was an AWS API Gateway, which can help provide a smooth migration from AWS gateways to Gloo Gateway.

field type description
body String Body of the HTTP request.
headers JSON object Mapping from request header keys to the request header values. Only single-value headers are supported.
statusCode Integer HTTP response status code (default 200).

The following simple payload is an example of the response that Gloo Gateway expects your Lambda function to return:

{
  "body": "hello, world"
}

Route table settings

In your RouteTable resource, the awsLambda.options.requestTransformation: REQUEST_DEFAULT and awsLambda.options.responseTransformation: RESPONSE_DEFAULT settings are enabled by default.

...
      forwardTo:
        destinations:
        - awsLambda:
            cloudProvider:
              name: aws-provider
              namespace: gloo-mesh
              cluster: $CLUSTER_NAME
            function: test-lambda
            options:
              requestTransformation: REQUEST_DEFAULT
              responseTransformation: RESPONSE_DEFAULT

Additional transformations

Apply additional Gloo transformation policies, which allow you to customize the request and respone payloads for Lambda as needed.

For example, you might apply the following policy to any routes with the route: lambda label. This policy adds the request header request-transformation and response header response-transformation to the payloads for the Lambda functions.

apiVersion: trafficcontrol.policy.gloo.solo.io/v2
kind: TransformationPolicy
metadata:
  annotations:
    cluster.solo.io/cluster: ""
  name: basic-auth
  namespace: bookinfo
spec:
  applyToRoutes:
  - route:
      labels:
        route: lambda
  config:
    request:
      injaTemplate:
        headers:
          request:
            text: request-transformation
    response:
      injaTemplate:
        headers:
          response:
            text: response-transformation

Transformation policies that you apply to Lambda routes are applied in addition to the existing transformations that are set in the awsLambda.options.requestTransformation and awsLambda.options.responseTransformation route table settings. If you want to disable those payload transformations, you can set requestTransformation: REQUEST_DISABLE and responseTransformation: RESPONSE_DISABLE in your route table resource.