Skip to content
This repository was archived by the owner on Nov 9, 2022. It is now read-only.

Commit edf1649

Browse files
committed
feat: Updated variable name in notification module
1 parent fa11cfe commit edf1649

File tree

3 files changed

+52
-7
lines changed

3 files changed

+52
-7
lines changed

examples/notification/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.zip

examples/notification/main.tf

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,54 @@ module "s3_bucket" {
1313
force_destroy = true
1414
}
1515

16+
#############################################
17+
# Using packaged function from Lambda module
18+
#############################################
19+
20+
locals {
21+
package_url = "https://raw.githubusercontent.com/terraform-aws-modules/terraform-aws-lambda/master/examples/fixtures/python3.8-zip/existing_package.zip"
22+
downloaded = "downloaded_package_${md5(local.package_url)}.zip"
23+
}
24+
25+
resource "null_resource" "download_package" {
26+
triggers = {
27+
downloaded = local.downloaded
28+
}
29+
30+
provisioner "local-exec" {
31+
command = "curl -L -o ${local.downloaded} ${local.package_url}"
32+
}
33+
}
34+
35+
data "null_data_source" "downloaded_package" {
36+
inputs = {
37+
id = null_resource.download_package.id
38+
filename = local.downloaded
39+
}
40+
}
41+
1642
module "lambda_function1" {
17-
source = "terraform-aws-modules/cloudwatch/aws//examples/fixtures/aws_lambda_function"
43+
source = "terraform-aws-modules/lambda/aws"
44+
version = "~> 1.0"
45+
46+
function_name = "${random_pet.this.id}-lambda1"
47+
handler = "index.lambda_handler"
48+
runtime = "python3.8"
49+
50+
create_package = false
51+
local_existing_package = data.null_data_source.downloaded_package.outputs["filename"]
1852
}
1953

2054
module "lambda_function2" {
21-
source = "terraform-aws-modules/cloudwatch/aws//examples/fixtures/aws_lambda_function"
55+
source = "terraform-aws-modules/lambda/aws"
56+
version = "~> 1.0"
57+
58+
function_name = "${random_pet.this.id}-lambda2"
59+
handler = "index.lambda_handler"
60+
runtime = "python3.8"
61+
62+
create_package = false
63+
local_existing_package = data.null_data_source.downloaded_package.outputs["filename"]
2264
}
2365

2466
module "sns_topic1" {
@@ -38,20 +80,21 @@ module "all_notifications" {
3880
source = "../../modules/notification"
3981

4082
bucket = module.s3_bucket.this_s3_bucket_id
41-
create = false
4283

4384
// 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.
4485

4586
lambda_notifications = {
4687
lambda1 = {
47-
lambda_function_arn = module.lambda_function1.this_lambda_function_arn
88+
function_arn = module.lambda_function1.this_lambda_function_arn
89+
function_name = module.lambda_function1.this_lambda_function_name
4890
events = ["s3:ObjectCreated:Put"]
4991
filter_prefix = "prefix/"
5092
filter_suffix = ".json"
5193
}
5294

5395
lambda2 = {
54-
lambda_function_arn = module.lambda_function2.this_lambda_function_arn
96+
function_arn = module.lambda_function2.this_lambda_function_arn
97+
function_name = module.lambda_function2.this_lambda_function_name
5598
events = ["s3:ObjectCreated:Post"]
5699
}
57100
}

modules/notification/main.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ resource "aws_s3_bucket_notification" "this" {
1616

1717
content {
1818
id = lambda_function.key
19-
lambda_function_arn = lambda_function.value.lambda_function_arn
19+
lambda_function_arn = lambda_function.value.function_arn
2020
events = lambda_function.value.events
2121
filter_prefix = lookup(lambda_function.value, "filter_prefix", null)
2222
filter_suffix = lookup(lambda_function.value, "filter_suffix", null)
@@ -60,7 +60,8 @@ resource "aws_lambda_permission" "allow" {
6060

6161
statement_id_prefix = "AllowLambdaS3BucketNotification-"
6262
action = "lambda:InvokeFunction"
63-
function_name = each.value.lambda_function_arn
63+
function_name = each.value.function_name
64+
qualifier = lookup(each.value, "qualifier", null)
6465
principal = "s3.amazonaws.com"
6566
source_arn = local.bucket_arn
6667
}

0 commit comments

Comments
 (0)