Use this resource to invoke a lambda function. The lambda function is invoked with the RequestResponse invocation type.
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"]
}
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"
})
}
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:
action
- Action Terraform performs on the resource. Values are create
, update
, or delete
.prev_input
- Input JSON payload from the previous invocation. This can be used to handle update and delete events.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"
}
}
}
The following arguments are required:
function_name
- (Required) Name of the lambda function.input
- (Required) JSON payload to the lambda function.The following arguments are optional:
lifecycle_scope
- (Optional) Lifecycle scope of the resource to manage. Valid values are CREATE_ONLY
and CRUD
. Defaults to CREATE_ONLY
. CREATE_ONLY
will invoke the function only on creation or replacement. CRUD
will invoke the function on each lifecycle event, and augment the input JSON payload with additional lifecycle information.qualifier
- (Optional) Qualifier (i.e., version) of the lambda function. Defaults to $LATEST
.terraform_key
- (Optional) The JSON key used to store lifecycle information in the input JSON payload. Defaults to tf
. This additional key is only included when lifecycle_scope
is set to CRUD
.triggers
- (Optional) Map of arbitrary keys and values that, when changed, will trigger a re-invocation. To force a re-invocation without changing these keys/values, use the terraform taint
command.This resource exports the following attributes in addition to the arguments above:
result
- String result of the lambda function invocation.