Resource: aws_lambda_invocation

Use this resource to invoke a lambda function. The lambda function is invoked with the RequestResponse invocation type.

Example Usage

Basic Example

resource "aws_lambda_invocation" "example" {
  function_name = aws_lambda_function.lambda_function_test.function_name

  input = jsonencode({
    key1 = "value1"
    key2 = "value2"
  })
}

output "result_entry" {
  value = jsondecode(aws_lambda_invocation.example.result)["key1"]
}

Dynamic Invocation Example Using Triggers

resource "aws_lambda_invocation" "example" {
  function_name = aws_lambda_function.lambda_function_test.function_name

  triggers = {
    redeployment = sha1(jsonencode([
      aws_lambda_function.example.environment
    ]))
  }

  input = jsonencode({
    key1 = "value1"
    key2 = "value2"
  })
}

CRUD Lifecycle Scope

resource "aws_lambda_invocation" "example" {
  function_name = aws_lambda_function.lambda_function_test.function_name

  input = jsonencode({
    key1 = "value1"
    key2 = "value2"
  })

  lifecycle_scope = "CRUD"
}

The key tf gets added with subkeys:

When the resource from the example above is created, the Lambda will get following JSON payload:

{
  "key1": "value1",
  "key2": "value2",
  "tf": {
    "action": "create",
    "prev_input": null
  }
}

If the input value of key1 changes to "valueB", then the lambda will be invoked again with the following JSON payload:

{
  "key1": "valueB",
  "key2": "value2",
  "tf": {
    "action": "update",
    "prev_input": {
      "key1": "value1",
      "key2": "value2"
    }
  }
}

When the invocation resource is removed, the final invocation will have the following JSON payload:

{
  "key1": "valueB",
  "key2": "value2",
  "tf": {
    "action": "delete",
    "prev_input": {
      "key1": "valueB",
      "key2": "value2"
    }
  }
}

Argument Reference

The following arguments are required:

The following arguments are optional:

Attribute Reference

This resource exports the following attributes in addition to the arguments above: