ValidationException on aws_lambda_event_source_mapping



在尝试启动DynamoDb触发的lambda时,我经常收到以下错误:

Error: error creating Lambda Event Source Mapping (): ValidationException:
status code: 400, request id: 2e09272b-68e5-4713-b083-c95db9dbad6e
on dynamo.tf line 30, in resource "aws_lambda_event_source_mapping" "dynamodb_lambda_mapping":
30: resource "aws_lambda_event_source_mapping" "dynamodb_lambda_mapping" {

而且不知道它在说什么,也不知道如何调试它。这就是代码:

resource "aws_dynamodb_table" "connections_dynamodb_table" {
name           = "tf-connections"
billing_mode   = "PROVISIONED"
hash_key       = "connectionId"
read_capacity  = 5
write_capacity = 5
attribute {
name = "connectionId"
type = "S"
}
}

data "archive_file" "dynamodb_triggered_lambda_code" {
type        = "zip"
source_dir  = "dynamodb_triggered_lambda_code"
output_path = "dynamodb_triggered_lambda_zipped_code.zip"
}
resource "aws_lambda_function" "dynamodb_triggered_lambda" {
function_name    = "tf_test_dynamodb_triggered_lambda"
role             = aws_iam_role.iam_for_lambda.arn
handler          = "index.handler"
source_code_hash = data.archive_file.dynamodb_triggered_lambda_code.output_base64sha256
filename         = "dynamodb_triggered_lambda_zipped_code.zip"
runtime          = "nodejs14.x"
}
resource "aws_lambda_event_source_mapping" "dynamodb_lambda_mapping" {
event_source_arn  = aws_dynamodb_table.connections_dynamodb_table.stream_arn
function_name     = aws_lambda_function.dynamodb_triggered_lambda.arn
starting_position = "LATEST"
}

aws_iam_role.iam_for_lambda资源位于同一目录中的另一个文件中。为了简洁起见,我放弃了它。。

您必须为表启用流

resource "aws_dynamodb_table" "connections_dynamodb_table" {
name           = "tf-connections"
billing_mode   = "PROVISIONED"
hash_key       = "connectionId"
stream_enabled = true
stream_view_type = "NEW_AND_OLD_IMAGES"
read_capacity  = 5
write_capacity = 5
attribute {
name = "connectionId"
type = "S"
}
}

我面临完全相同的错误消息和错误状态代码。在我的情况下,我使用了来自这个地形模块输出的错误lambda arn:https://registry.terraform.io/modules/terraform-aws-modules/lambda/aws/latest

您应该使用此模块的lambda_function_arn输出。

相关内容

  • 没有找到相关文章

最新更新