KrakenD 1.0 is here!. Read our announcement.

Recent changes

Edit this page

Integration with AWS Lambda functions

The Lambda integration allows you to invoke Amazon Lambda functions on a KrakenD endpoint call. The content returned by the lambda function can be treated and manipulated as any other backend.

The payload that is sent to the Lambda function comes from the request and depends on the method used by the endpoint:

  • Method GET: The payload contains all the parameters of the request.
  • Non-GET methods: The payload is defined by the content of the body in the request.

You don’t need to set an Amazon API Gateway in the middle as KrakenD does this job for you.

Lambda configuration

The inclusion requires you to add the code in the extra_config of your backend section, using the github.com/devopsfaith/krakend-lambda namespace.

The supported parameters are:

  • function_name: Name of the lambda function as saved in the AWS service.
  • function_param_name: The endpoint {placeholder} that sets the function name. You have to choose between function_name and function_param_name but not both.
  • region: The AWS identifier region (e.g.: us-east-1, eu-west-2, etc. )
  • max_retries: Maximum times you want to execute the function until you have a successful response.
  • endpoint: An optional parameter to customize the Lambda endpoint to call. Useful when Localstack is used for testing.

Authentication

The KrakenD machine needs to have the AWS credentials in the default file, ~/.aws/credentials.

When setting the credentials make sure that the lamdba is callable within the KrakenD box with the credentials provided. This translates in having an IAM user with a policy and execution role that let you invoke the function.

Examples

Associate a lambda to a backend

When the KrakenD endpoint is attached to the same Lambda, use this configuration:

"backend": [
{
    "github.com/devopsfaith/krakend-lambda": {
        "function_name": "lambda-function",
        "region": "us-west1",
        "max_retries": 1
    }
}

Take the lambda from the URL

When the name of the Lambda to depends on a parameter passed in the endpoint, use this configuration instead:

"endpoint": "/call-a-lambda/{lambda},
"backend": [
{
    "github.com/devopsfaith/krakend-lambda": {
        "function_param_name": "lambda",
        "region": "us-west1",
        "max_retries": 1
    }
}

In this example, the function_param_name is telling us which is the placeholder in the endpoint setting the lambda. In this case, {lambda}.

Following the code, a call GET /call-a-lambda/my-lambda would produce a call to the my-lambda function in AWS.

Unresolved issues?

The documentation is only a piece of the help you can get! Whether you are looking for Open Source or Enterprise support, see more support channels that can help you.