简体   繁体   中英

terraform - how to add s3 Object Created trigger for lambda

How do I add a trigger to aws lambda using terraform? the desired trigger is s3, object created all.

my terraform source code arouond the lambda is:

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}"
  }
}

trying to figure out how do I add the trigger. via the aws console it is super simple.

After some reading in: https://www.terraform.io/docs/providers/aws/r/s3_bucket_notification.html

the solution is:

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"
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM