Default request and response payloads

When a workload in your Gloo Mesh Gateway environment sends a request to your Lambda function, Gateway applies a default transformation to the payload. When the function returns the response, Gloo Mesh 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 Mesh Gateway format. Note that the default request and response transformations require your ingress gateway to run Istio 1.15.1 or later.

Request format

When you send a request to your Lambda function, Gloo Mesh 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 fieldTypeDescription
headersJSON objectMapping from request header keys to the request header values. Only single-value headers are supported.
bodyStringBody of the HTTP request.
httpMethodStringMethod of the HTTP request.
pathStringPath of the HTTP request, without the query string.
queryStringStringQuery 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 Mesh 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 Mesh 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 Mesh Gateway.

fieldtypedescription
bodyStringBody of the HTTP request.
headersJSON objectMapping from request header keys to the request header values. Only single-value headers are supported.
statusCodeIntegerHTTP response status code (default 200).

The following simple payload is an example of the response that Gloo Mesh 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 response 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