Consul
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.
Configuration specifications
The Lambda Envoy extension has the following arguments:
Arguments | Type | Default | Description |
---|---|---|---|
ARN | string | Required | Specifies the AWS ARN for the service's Lambda. |
InvocationMode | boolean | false | Determines if Consul configures the Lambda to be invoked using the synchronous or asynchronous invocation mode. |
PayloadPassthrough | string | synchronous | Determines if the body Envoy receives is converted to JSON or directly passed to Lambda. |
Unlike manual lambda registration, the Envoy extension infers the region from the ARN.
Workflow
Complete the following steps to use the Lambda Envoy extension:
- Configure EnvoyExtensions through
service-defaults
. - Apply the configuration entry.
Configure EnvoyExtensions
To use the Lambda Envoy extension, you must configure and apply a service-defaults
configuration entry. Consul uses service default's name as the Consul service name for the Lambda function. Downstream services also use the name to invoke the Lambda.
The following example configures the Lambda Envoy extension to create a service named lambda-1234
in the mesh that can invoke the associated Lambda function.
lambda-envoy-extension.hcl
Kind = "service-defaults"
Name = "lambda-1234"
Protocol = "http"
EnvoyExtensions {
Name = "builtin/aws/lambda"
Arguments = {
ARN = "arn:aws:lambda:us-west-2:111111111111:function:lambda-1234"
}
}
For a full list of parameters for EnvoyExtensions
, refer to the service-defaults
.
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.
$ consul config write lambda-envoy-extension.hcl
Examples
The following example configuration adds a single Lambda function running in two regions into the mesh. You can use the lambda-1234
service name to invoke it, as if it was any other service in the mesh.
lambda-envoy-extension.hcl
Kind = "service-defaults"
Name = "lambda-1234"
Protocol = "http"
EnvoyExtensions {
Name = "builtin/aws/lambda"
Arguments = {
payloadPassthrough: false
arn: arn:aws:lambda:us-west-2:111111111111:function:lambda-1234
}
}
EnvoyExtensions {
Name = "builtin/aws/lambda"
Arguments = {
payloadPassthrough: false
arn: arn:aws:lambda:us-east-1:111111111111:function:lambda-1234
}
}