gpt4 book ai didi

amazon-web-services - 在 Terraform 中创建 S3 存储桶通知时出错

转载 作者:行者123 更新时间:2023-12-04 08:13:56 24 4
gpt4 key购买 nike

我在创建存储桶通知以触发 Lambda 函数时遇到问题。错误:

Error putting S3 notification configuration: InvalidArgument: Unable to validate the following destination configurations
status code: 400

我了解到类似的问题可能是由创建资源的顺序或缺少 Lambda 权限引起的。但是,我尝试在代码中包含 depends_on 以及应用模板几次并在中间等待。我正在使用限制最少的 Lambda 策略。我还尝试使用 Terraform documentation 中的确切示例代码,但这给了我一个完全不同的错误。

如果在控制台中创建,完全相同的设置可以正常工作。

这是我的代码中有问题的部分:

resource "aws_lambda_function" "writeUsersToDB" {
filename = "writeUsersToDB.zip"
function_name = "writeUsersToDB"
role = "arn:aws:iam::0000000:role/AWSLambdaFullAccess"
handler = "main.lambda_handler"
memory_size = 256
timeout = 900
source_code_hash = filebase64sha256("writeUsersToDB.zip")
runtime = "python3.8"
environment {variables = local.parameters}
layers = [ "arn:aws:lambda:eu-west-2:0000000:layer:pandas-pandas-schema-numpy:1" ]
}



resource "aws_s3_bucket_notification" "event" {
bucket = aws_s3_bucket.user_data.id

lambda_function {
lambda_function_arn = aws_lambda_function.writeUsersToDB.arn
events = ["s3:ObjectCreated:*"]
filter_suffix = ".csv"
}
depends_on = [aws_lambda_function.writeUsersToDB]
}


resource "aws_s3_bucket" "user_data" {
bucket = "nameofthebucket"
}

最佳答案

您缺少aws_lambda_permission :

resource "aws_lambda_permission" "example" {
statement_id = "AllowExecutionFromS3Bucket"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.writeUsersToDB.function_name
principal = "s3.amazonaws.com"
source_arn = aws_s3_bucket.user_data.arn
}


关于amazon-web-services - 在 Terraform 中创建 S3 存储桶通知时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65805090/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com