从 DynamoDB 触发 lambda 函数
trigger lambda function from DynamoDB
每次我的发电机 table 收到新物品时,我都想 运行 一个 lambda 函数 trigger_lambda_function
。这就是我定义 table 和触发器的方式。但是,触发器没有按预期工作。
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"
}
terraform apply
后,我得到一个错误:
│ 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" {
我也尝试了 .arn
而不是 stream_arn
,但这也引发了错误。我还能尝试什么?
我遵循了触发器的文档:
https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_event_source_mapping
根据 aws_dynamodb_table
文档,stream_arn
仅在 stream_enabled
设置为 true
时可用。您可能希望将 stream_enabled = true
添加到您的 DynamoDB table 定义中。
默认情况下 stream_enabled
设置为 false
。您可以看到 aws_dynamodb_table
.
的所有默认值 here
每次我的发电机 table 收到新物品时,我都想 运行 一个 lambda 函数 trigger_lambda_function
。这就是我定义 table 和触发器的方式。但是,触发器没有按预期工作。
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"
}
terraform apply
后,我得到一个错误:
│ 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" {
我也尝试了 .arn
而不是 stream_arn
,但这也引发了错误。我还能尝试什么?
我遵循了触发器的文档: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_event_source_mapping
根据 aws_dynamodb_table
文档,stream_arn
仅在 stream_enabled
设置为 true
时可用。您可能希望将 stream_enabled = true
添加到您的 DynamoDB table 定义中。
默认情况下 stream_enabled
设置为 false
。您可以看到 aws_dynamodb_table
.