@@ -13,12 +13,54 @@ module "s3_bucket" {
13
13
force_destroy = true
14
14
}
15
15
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
+
16
42
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" ]
18
52
}
19
53
20
54
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" ]
22
64
}
23
65
24
66
module "sns_topic1" {
@@ -38,20 +80,21 @@ module "all_notifications" {
38
80
source = " ../../modules/notification"
39
81
40
82
bucket = module. s3_bucket . this_s3_bucket_id
41
- create = false
42
83
43
84
// 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.
44
85
45
86
lambda_notifications = {
46
87
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
48
90
events = [" s3:ObjectCreated:Put" ]
49
91
filter_prefix = " prefix/"
50
92
filter_suffix = " .json"
51
93
}
52
94
53
95
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
55
98
events = [" s3:ObjectCreated:Post" ]
56
99
}
57
100
}
0 commit comments