Skip to content

Commit bdebaf4

Browse files
CCM-12059: Improve Eventpub Lambda Build - Build only when changed
1 parent 0a6f3cc commit bdebaf4

3 files changed

Lines changed: 33 additions & 2 deletions

File tree

infrastructure/modules/eventpub/lambda_function.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ resource "aws_lambda_function" "main" {
99
memory_size = 128
1010
timeout = 20
1111

12-
filename = archive_file.lambda.output_path
13-
source_code_hash = archive_file.lambda.output_base64sha256
12+
s3_bucket = aws_s3_object.lambda.bucket
13+
s3_key = aws_s3_object.lambda.key
14+
s3_object_version = aws_s3_object.lambda.version_id
1415

1516
logging_config {
1617
application_log_level = var.log_level
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
resource "aws_s3_object" "lambda" {
2+
bucket = var.function_s3_bucket
3+
key = "${local.csi}.zip"
4+
source = data.archive_file.lambda.output_path
5+
6+
source_hash = var.force_lambda_code_deploy ? data.archive_file.lambda.output_base64sha256 : null
7+
8+
metadata = {
9+
hash = data.archive_file.lambda.output_base64sha256
10+
function = local.csi
11+
commit = try(data.external.git_commit.result["sha"], "null")
12+
}
13+
14+
lifecycle {
15+
ignore_changes = [
16+
metadata["commit"]
17+
]
18+
}
19+
}

infrastructure/modules/eventpub/variables.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,14 @@ variable "force_destroy" {
123123
description = "When enabled will force destroy event-cache S3 bucket"
124124
default = false
125125
}
126+
127+
variable "function_s3_bucket" {
128+
type = string
129+
description = "The bucket to upload Lambda packages to"
130+
}
131+
132+
variable "force_lambda_code_deploy" {
133+
type = bool
134+
description = "If the lambda package in s3 has the same commit id tag as the terraform build branch, the lambda will not update automatically. Set to True if making changes to Lambda code from on the same commit for example during development"
135+
default = false
136+
}

0 commit comments

Comments
 (0)