Manual Lambda Function Registration

This topic describes how to manually register Lambda functions into Consul. Refer to Automate Lambda Function Registration for information about using the Lambda registrator to automate registration.

Requirements

Verify that your environment meets the requirements specified in Lambda Function Registration Requirements.

To manually register Lambda functions so that mesh services can invoke them, you must create and apply a service registration configuration for the Lambda function and write a service defaults configuration entry for the function.

Register a Lambda function

You can manually register Lambda functions if you are unable to automate the process using the Lambda registrator.

  1. Create a configuration for registering the service. You can copy the following example and replace <SERVICE_NAME> with your Consul service name for the Lambda function:

    Manual Registration - 图1

    lambda.json

    1. {
    2. "Node": "lambdas",
    3. "SkipNodeUpdate": true,
    4. "NodeMeta": {
    5. "external-node": "true",
    6. "external-probe": "true"
    7. },
    8. "Service": {
    9. "Service": "<SERVICE_NAME>"
    10. }
    11. }
  2. Save the configuration to lambda.json.

  3. Send the configuration to the catalog/register API endpoint to register the service, for example:

    1. $ curl --request PUT --data @lambda.json localhost:8500/v1/catalog/register
  4. Create the service-defaults configuration entry and include the AWS tags used to invoke the Lambda function in the EnvoyExtensions configuration. Refer to Supported EnvoyExtension arguments for more information.

The following example creates a service-defaults configuration entry named lambda:

Manual Registration - 图2

lambda-service-defaults.hcl

  1. Kind = "service-defaults"
  2. Name = "<SERVICE_NAME>"
  3. Protocol = "http"
  4. EnvoyExtensions = [
  5. {
  6. "Name": "builtin/aws/lambda",
  7. "Arguments": {
  8. "Region": "us-east-2",
  9. "ARN": "<INSERT ARN HERE>",
  10. "PayloadPassthrough": true
  11. }
  12. }
  13. ]
  1. Issue the consul config write command to store the configuration entry. For example:

    1. $ consul config write lambda-service-defaults.hcl

Supported EnvoyExtension arguments

The lambda Envoy extension supports the following arguments:

  • ARN (string) - Specifies the AWS ARN for the service’s Lambda. ARN must be set to a valid Lambda function ARN.
  • Region (string) - Specifies the AWS region the Lambda is running in. Region must be set to a valid AWS region where the Lambda function exists.
  • PayloadPassthrough (boolean: false) - Determines if the body Envoy receives is converted to JSON or directly passed to Lambda.
  • InvocationMode (string: synchronous) - Determines if Consul configures the Lambda to be invoked using the synchronous or asynchronous invocation mode.