aws-lambda
Invokes an AWS Lambda function as the upstream.
aws-lambdaPriority -1899What it does
aws-lambda answers the requests on a route from an AWS Lambda function instead of an upstream. The gateway calls the function at Function URI, with the key under API key or a request signed with the keys under IAM.
The client gets what the function answers, its status and its body, 200 and order 42 from the function in the example. The route in the example carries no upstream of its own.
When to use it
- An orders endpoint written as a Lambda function, published on the same host as the routes your own backend instances serve.
- A function behind AWS API Gateway that expects an API key, which the gateway adds so that no client ever holds it.
- A function URL protected by IAM, where the gateway signs each call with the keys of an IAM user.
- One path of an API moved to a function, a report export for example, while the rest stays on the backend.
Not for a backend of your own — see Upstream (Upstreams are the backends that routes and services send traffic to), a function hosted on Azure — see azure-functions (Invokes an Azure Function as the upstream) or code that runs inside the gateway itself — see serverless-pre-function (Runs Lua functions before the other plugins of a phase).
Set it up
Serve the route from a Lambda function invoked with an API key
Under Basics set Function URI to https://k3x9q2w7ab.execute-api.eu-central-1.amazonaws.com/prod/orders and fill Authorization as in the JSON below. Under Behavior set Timeout to 10000 milliseconds.
{
"function_uri": "https://k3x9q2w7ab.execute-api.eu-central-1.amazonaws.com/prod/orders",
"authorization": {
"apikey": "<secret>"
},
"timeout": 10000
}
Things to know
- API key — The key reaches the function in the
x-api-keyheader. In the example the function answers only a request that carries it, and the client receives its200. - Authorization — With both set, the stored API key is sent and nothing is signed, unless the request brings its own x-api-key, which IAM then signs.
- IAM — A request that carries the same header twice fails with 500 before the call, but only where these credentials sign it.
- IAM — IAM keys without the Secret access key are refused when you save.
- Function URI — An empty Function URI is refused when you save.
- AdviceGive the gateway an IAM user of its own that may invoke this function and nothing else.
Settings
The fields as the console shows them, section by section.
Basics
function_uristringRequiredThe function's full URL, to which whatever a route wildcard matched is appended.
https://abc123.execute-api.eu-central-1.amazonaws.com/prod/ordersauthorizationobjectauthorization.apikeystringStored on the engine and shown only to roles that manage this object.
authorization.iamobjectauthorization.iam.accesskeystringRequiredThe access key ID the request is signed with, from the AWS IAM console. Stored on the engine and shown only to roles that manage this object.
authorization.iam.secretkeystringRequiredThe secret access key the request is signed with, from the AWS IAM console. Stored on the engine and shown only to roles that manage this object.
authorization.iam.aws_regionstringdefault us-east-1The AWS region the function runs in, used in the request signature.
authorization.iam.servicestringdefault execute-apiThe AWS service name in the request signature: execute-api for a function behind API Gateway, lambda for a function URL.
Behavior
timeoutintegerdefault 3000ssl_verifybooleandefault trueAdvanced
max_req_body_sizeintegerdefault 67108864The largest request body in bytes that is forwarded, where a larger one is rejected with 400.
keepalivebooleandefault truekeepalive_poolintegerdefault 5keepalive_timeoutintegerdefault 60000