Invoke Lambda functions in Envoy proxy

The Lambda Envoy extension configures outbound traffic on upstream dependencies allowing mesh services to properly invoke AWS Lambda functions. Lambda functions appear in the catalog as any other Consul service.

You can only enable the Lambda extension through service-defaults. This is because the Consul uses the service-defaults configuration entry name as the catalog name for the Lambda functions.

Specification

The Lambda Envoy extension has the following arguments:

ArgumentsDescription
ARNSpecifies the AWS ARN for the service’s Lambda.
InvocationModeDetermines if Consul configures the Lambda to be invoked using the synchronous or asynchronous invocation mode.
PayloadPassthroughDetermines if the body Envoy receives is converted to JSON or directly passed to Lambda.

Be aware that unlike manual lambda registration, region is inferred from the ARN when specified through an Envoy extension.

Workflow

There are two steps to configure the Lambda Envoy extension:

  1. Configure EnvoyExtensions through service-defaults.
  2. Apply the configuration entry.

Configure EnvoyExtensions

To use the Lambda Envoy extension, you must configure and apply a service-defaults configuration entry. Consul uses the name of the entry as the Consul service name for the Lambdas in the catalog. Downstream services also use the name to invoke the Lambda.

The following example configures the Lambda Envoy extension to create a service named lambda in the mesh that can invoke the associated Lambda function.

Invoke Lambda functions in Envoy proxies - 图1

lambda-envoy-extension.hcl

  1. Kind = "service-defaults"
  2. Name = "lambdaInvokingApp"
  3. Protocol = "http"
  4. EnvoyExtensions {
  5. Name = "builtin/aws/lambda"
  6. Arguments = {
  7. ARN = "arn:aws:lambda:us-west-2:111111111111:function:lambda-1234"
  8. }
  9. }

Invoke Lambda functions in Envoy proxies - 图2

lambda-envoy-extension.json

  1. {
  2. "kind": "service-defaults",
  3. "name": "lambdaInvokingApp",
  4. "protocol": "http",
  5. "envoy_extensions": [{
  6. "name": "builtin/aws/lambda",
  7. "arguments": {
  8. "arn": "arn:aws:lambda:us-west-2:111111111111:function:lambda-1234"
  9. }
  10. }]
  11. }

Invoke Lambda functions in Envoy proxies - 图3

lambda-envoy-extension.yaml

  1. apiVersion: consul.hashicorp.com/v1alpha1
  2. kind: ServiceDefaults
  3. metadata:
  4. name: lambda
  5. spec:
  6. protocol: http
  7. envoyExtensions:
  8. name = "builtin/aws/lambda"
  9. arguments:
  10. arn: arn:aws:lambda:us-west-2:111111111111:function:lambda-1234

For a full list of parameters for EnvoyExtensions, refer to the service-defaults and proxy-defaults configuration entries reference documentation.

Note: You can only enable the Lambda extension through service-defaults.

Refer to Configuration specification section to find a full list of arguments for the Lambda Envoy extension.

Apply the configuration entry

Apply the service-defaults configuration entry.

  1. $ consul config write lambda-envoy-extension.hcl
  1. $ consul config write lambda-envoy-extension.json
  1. $ kubectl apply lambda-envoy-extension.yaml

Examples

In the following example, the Lambda Envoy extension adds a single Lambda function running in two regions into the mesh. Then, you can use the lambda service name to invoke it, as if it was any other service in the mesh.

Invoke Lambda functions in Envoy proxies - 图4

lambda-envoy-extension.json

  1. Kind = "service-defaults"
  2. Name = "lambda"
  3. Protocol = "http"
  4. EnvoyExtensions {
  5. Name = "builtin/aws/lambda"
  6. Arguments = {
  7. payloadPassthrough: false
  8. arn: arn:aws:lambda:us-west-2:111111111111:function:lambda-1234
  9. }
  10. }
  11. EnvoyExtensions {
  12. Name = "builtin/aws/lambda"
  13. Arguments = {
  14. payloadPassthrough: false
  15. arn: arn:aws:lambda:us-east-1:111111111111:function:lambda-1234
  16. }
  17. }