Skip to content

Commit 92c9b86

Browse files
authored
fix: make lambda function depend on the Cloudwatch log group (#133)
1 parent 0777961 commit 92c9b86

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

examples/complete/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module "lambda_function" {
2626
source_path = "${path.module}/../fixtures/python3.8-app1"
2727

2828
store_on_s3 = true
29-
s3_bucket = module.s3_bucket.this_s3_bucket_id
29+
s3_bucket = module.s3_bucket.s3_bucket_id
3030

3131
layers = [
3232
module.lambda_layer_local.this_lambda_layer_arn,
@@ -183,7 +183,7 @@ module "lambda_layer_s3" {
183183
source_path = "${path.module}/../fixtures/python3.8-app1"
184184

185185
store_on_s3 = true
186-
s3_bucket = module.s3_bucket.this_s3_bucket_id
186+
s3_bucket = module.s3_bucket.s3_bucket_id
187187
}
188188

189189
##############

main.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ resource "aws_lambda_function" "this" {
8383

8484
tags = var.tags
8585

86-
depends_on = [null_resource.archive, aws_s3_bucket_object.lambda_package]
86+
# Depending on the log group is necessary to allow Terraform to create the log group before AWS can.
87+
# When a lambda function is invoked, AWS creates the log group automatically if it doesn't exist yet.
88+
# Without the dependency, this can result in a race condition if the lambda function is invoked before
89+
# Terraform can create the log group.
90+
depends_on = [null_resource.archive, aws_s3_bucket_object.lambda_package, aws_cloudwatch_log_group.lambda]
8791
}
8892

8993
resource "aws_lambda_layer_version" "this" {

0 commit comments

Comments
 (0)