如何使用terraform为aws lambda添加触发器? 所需的触发器是s3,对象全部创建。
我的terraform源代码对lambda是:
module "s3-object-created-lambda" {
source = "../../../../../modules/lambda"
s3_bucket = "${var.s3_lambda_bucket}"
s3_key = "${var.s3_lambda_key}"
name = "${var.lambda_some_name}"
handler = "code.handler"
env = {
lambda_name = "${var.lambda_base_name}"
lambda_version = "${var.lambda_version}"
}
}
试图找出如何添加触发器。 通过aws控制台,它非常简单。
答案 0 :(得分:5)
阅读后: https://www.terraform.io/docs/providers/aws/r/s3_bucket_notification.html
解决方案是:
resource "aws_s3_bucket_notification" "bucket_notification" {
bucket = "${data.terraform_remote_state.stack.bucket_id}"
lambda_function {
lambda_function_arn = "${module.some_lambda.lambda_arn}"
events = ["s3:ObjectCreated:*"]
filter_prefix = "${var.cluster_name}/somepath/"
filter_suffix = ".txt"
}
}