From a4f9f1a346f134690c599358cc0940c326132104 Mon Sep 17 00:00:00 2001 From: Andrew Hlynskyi Date: Wed, 10 Jun 2020 15:49:50 +0300 Subject: [PATCH 1/3] Fixed misprint in a local_file.archive_plan permission --- package.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.tf b/package.tf index 58da156b..dd4c3851 100644 --- a/package.tf +++ b/package.tf @@ -37,7 +37,7 @@ resource "local_file" "archive_plan" { content = data.external.archive_prepare[0].result.build_plan filename = data.external.archive_prepare[0].result.build_plan_filename directory_permission = "0755" - file_permission = "0664" + file_permission = "0644" } # Build the zip archive whenever the filename changes. From ee743df9086827d53d69867fd970c10e98a6852c Mon Sep 17 00:00:00 2001 From: Andrew Hlynskyi Date: Wed, 10 Jun 2020 15:35:47 +0300 Subject: [PATCH 2/3] Write zip files into a temp file first This makes all premature zip file reads more explicit. Also this may fix issues with reading incomplete zip files. --- package.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/package.py b/package.py index 73c2df52..e73f9075 100644 --- a/package.py +++ b/package.py @@ -249,13 +249,19 @@ def str_int_to_timestamp(s): logger.info("creating '%s' archive", zip_filename) - with zipfile.ZipFile(zip_filename, "w", compression) as zf: - for base_dir in base_dirs: - logger.info("adding content of directory '%s'", base_dir) - with cd(base_dir, silent=True): - for path in emit_dir_files('.'): - logger.info("adding '%s'", path) - write(zf, path, path, date_time=date_time) + tmp_zip_filename = '{}.tmp'.format(zip_filename) + try: + with zipfile.ZipFile(tmp_zip_filename, "w", compression) as zf: + for base_dir in base_dirs: + logger.info("adding content of directory '%s'", base_dir) + with cd(base_dir, silent=True): + for path in emit_dir_files('.'): + logger.info("adding '%s'", path) + write(zf, path, path, date_time=date_time) + except Exception: + os.unlink(tmp_zip_filename) + else: + os.replace(tmp_zip_filename, zip_filename) return zip_filename From 8f5f08e54ef3ab56db362302bd748faa468c4f86 Mon Sep 17 00:00:00 2001 From: Andrew Hlynskyi Date: Wed, 10 Jun 2020 15:47:38 +0300 Subject: [PATCH 3/3] Added dependency for aws_s3_bucket_object, fixes #15 --- main.tf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.tf b/main.tf index af047164..cece522b 100644 --- a/main.tf +++ b/main.tf @@ -96,6 +96,8 @@ resource "aws_s3_bucket_object" "lambda_package" { storage_class = var.s3_object_storage_class tags = merge(var.tags, var.s3_object_tags) + + depends_on = [null_resource.archive] } resource "aws_lambda_provisioned_concurrency_config" "current_version" {