Every time a new item arrives in my dynamo table, I want to run a lambda function trigger_lambda_function
. This is how I define my table and trigger. However, the trigger does not work as expected.
resource "aws_dynamodb_table" "filenames" {
name = local.dynamodb_table_filenames
billing_mode = "PROVISIONED"
read_capacity = 1000
write_capacity = 1000
hash_key = "filename"
#range_key = ""
attribute {
name = "filename"
type = "S"
}
tags = var.tags
}
resource "aws_lambda_event_source_mapping" "allow_dynamodb_table_to_trigger_lambda" {
event_source_arn = aws_dynamodb_table.filenames.stream_arn
function_name = aws_lambda_function.trigger_stepfunction_lambda.arn
starting_position = "LATEST"
}
Upon terraform apply
, I get an error that:
│ Error: error creating Lambda Event Source Mapping (): InvalidParameterValueException: Unrecognized event source.
│ {
│ RespMetadata: {
│ StatusCode: 400,
│ RequestID: "5ae68da6-3f6d-4adb-b104-72ae584dbca7"
│ },
│ Message_: "Unrecognized event source.",
│ Type: "User"
│ }
│
│ with module.ingest_system["alpegatm"].aws_lambda_event_source_mapping.allow_dynamodb_table_to_trigger_lambda,
│ on ../../modules/ingest_system/dynamo.tf line 39, in resource "aws_lambda_event_source_mapping" "allow_dynamodb_table_to_trigger_lambda":
│ 39: resource "aws_lambda_event_source_mapping" "allow_dynamodb_table_to_trigger_lambda" {
I also tried .arn
instead of stream_arn
but that threw an error too. What else could I try?
I followed the documentation for the trigger: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_event_source_mapping
CodePudding user response:
From the aws_dynamodb_table
docs, stream_arn
is only available if stream_enabled
is set to true
. You might want to add stream_enabled = true
to your DynamoDB table definition.
By default stream_enabled
is set to false
. You can see all the default values here for aws_dynamodb_table
.