Skip to content

Commit 25a519c

Browse files
authored
Upload artifact to an S3 bucket (#3)
* Upload artifact to an S3 bucket * remove double encryption * try removing period in key name * test removing etag * try removing tags * try using base64 of content * Change the key * hardcode source for test * reset to desired state Co-authored-by: dmattia <[email protected]>
1 parent beec0df commit 25a519c

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

main.tf

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,37 @@ data archive_file zip_file_for_lambda {
3434
}
3535
}
3636

37+
/**
38+
* Upload the build artifact zip file to S3.
39+
*
40+
* Doing this makes the plans more resiliant, where it won't always
41+
* appear that the function needs to be updated
42+
*/
43+
resource aws_s3_bucket_object artifact {
44+
bucket = var.s3_artifact_bucket
45+
key = "${var.name}.zip"
46+
source = data.archive_file.zip_file_for_lambda.output_path
47+
etag = filemd5(data.archive_file.zip_file_for_lambda.output_path)
48+
tags = var.tags
49+
}
50+
3751
/**
3852
* Create the Lambda function. Each new apply will publish a new version.
3953
*/
4054
resource aws_lambda_function lambda {
4155
function_name = var.name
4256
description = var.description
4357

44-
publish = true
45-
filename = data.archive_file.zip_file_for_lambda.output_path
46-
source_code_hash = data.archive_file.zip_file_for_lambda.output_base64sha256
47-
handler = var.handler
48-
runtime = var.runtime
49-
role = aws_iam_role.lambda_at_edge.arn
50-
tags = var.tags
58+
# Find the file from S3
59+
s3_bucket = var.s3_artifact_bucket
60+
s3_key = aws_s3_bucket_object.artifact.id
61+
s3_object_version = aws_s3_bucket_object.artifact.version_id
62+
63+
publish = true
64+
handler = var.handler
65+
runtime = var.runtime
66+
role = aws_iam_role.lambda_at_edge.arn
67+
tags = var.tags
5168

5269
lifecycle {
5370
ignore_changes = [

variables.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ variable description {
66
description = "Description of what the Lambda@Edge Function does"
77
}
88

9+
variable s3_artifact_bucket {
10+
description = "Name of the S3 bucket to upload versioned artifacts to"
11+
}
12+
913
variable tags {
1014
type = map(string)
1115
description = "Tags to apply to all resources that support them"
12-
default = {}
16+
default = {}
1317
}
1418

1519
variable lambda_code_source_dir {

0 commit comments

Comments
 (0)