Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 683
Amit Talmor Avatar asked Jan 30 '23 02:01

Amit Talmor


1 Answers

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"
  }
}
like image 190
Amit Talmor Avatar answered Feb 03 '23 22:02

Amit Talmor