Commit edf16498 authored by Anton Babenko's avatar Anton Babenko

feat: Updated variable name in notification module

parent fa11cfef
......@@ -13,12 +13,54 @@ module "s3_bucket" {
force_destroy = true
}
#############################################
# Using packaged function from Lambda module
#############################################
locals {
package_url = "https://raw.githubusercontent.com/terraform-aws-modules/terraform-aws-lambda/master/examples/fixtures/python3.8-zip/existing_package.zip"
downloaded = "downloaded_package_${md5(local.package_url)}.zip"
}
resource "null_resource" "download_package" {
triggers = {
downloaded = local.downloaded
}
provisioner "local-exec" {
command = "curl -L -o ${local.downloaded} ${local.package_url}"
}
}
data "null_data_source" "downloaded_package" {
inputs = {
id = null_resource.download_package.id
filename = local.downloaded
}
}
module "lambda_function1" {
source = "terraform-aws-modules/cloudwatch/aws//examples/fixtures/aws_lambda_function"
source = "terraform-aws-modules/lambda/aws"
version = "~> 1.0"
function_name = "${random_pet.this.id}-lambda1"
handler = "index.lambda_handler"
runtime = "python3.8"
create_package = false
local_existing_package = data.null_data_source.downloaded_package.outputs["filename"]
}
module "lambda_function2" {
source = "terraform-aws-modules/cloudwatch/aws//examples/fixtures/aws_lambda_function"
source = "terraform-aws-modules/lambda/aws"
version = "~> 1.0"
function_name = "${random_pet.this.id}-lambda2"
handler = "index.lambda_handler"
runtime = "python3.8"
create_package = false
local_existing_package = data.null_data_source.downloaded_package.outputs["filename"]
}
module "sns_topic1" {
......@@ -38,20 +80,21 @@ module "all_notifications" {
source = "../../modules/notification"
bucket = module.s3_bucket.this_s3_bucket_id
create = false
// Common error - Error putting S3 notification configuration: InvalidArgument: Configuration is ambiguously defined. Cannot have overlapping suffixes in two rules if the prefixes are overlapping for the same event type.
lambda_notifications = {
lambda1 = {
lambda_function_arn = module.lambda_function1.this_lambda_function_arn
function_arn = module.lambda_function1.this_lambda_function_arn
function_name = module.lambda_function1.this_lambda_function_name
events = ["s3:ObjectCreated:Put"]
filter_prefix = "prefix/"
filter_suffix = ".json"
}
lambda2 = {
lambda_function_arn = module.lambda_function2.this_lambda_function_arn
function_arn = module.lambda_function2.this_lambda_function_arn
function_name = module.lambda_function2.this_lambda_function_name
events = ["s3:ObjectCreated:Post"]
}
}
......
......@@ -16,7 +16,7 @@ resource "aws_s3_bucket_notification" "this" {
content {
id = lambda_function.key
lambda_function_arn = lambda_function.value.lambda_function_arn
lambda_function_arn = lambda_function.value.function_arn
events = lambda_function.value.events
filter_prefix = lookup(lambda_function.value, "filter_prefix", null)
filter_suffix = lookup(lambda_function.value, "filter_suffix", null)
......@@ -60,7 +60,8 @@ resource "aws_lambda_permission" "allow" {
statement_id_prefix = "AllowLambdaS3BucketNotification-"
action = "lambda:InvokeFunction"
function_name = each.value.lambda_function_arn
function_name = each.value.function_name
qualifier = lookup(each.value, "qualifier", null)
principal = "s3.amazonaws.com"
source_arn = local.bucket_arn
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment