Skip to content

Commit 383e928

Browse files
committed
VED-470: Add missing permission. Move processed files to an archive prefix.
1 parent b80081d commit 383e928

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

mesh_processor/src/converter.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ def process_record(record: dict) -> None:
133133

134134
logger.info(f"Transfer complete for {file_key}")
135135

136+
move_file(bucket_name, file_key, bucket_name, f"archive/{file_key}")
137+
138+
logger.info(f"Archived {file_key}")
139+
136140

137141
def lambda_handler(event: dict, _context: dict) -> dict:
138142
success = True

mesh_processor/tests/test_converter.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,17 @@ def test_non_multipart_content_type(self):
4848
result = invoke_lambda("test-csv-file.csv")
4949
self.assertEqual(result["statusCode"], 200)
5050

51-
response = s3.get_object(Bucket="destination-bucket", Key="overridden-filename.csv")
52-
body = response["Body"].read().decode("utf-8")
51+
get_target_response = s3.get_object(Bucket="destination-bucket", Key="overridden-filename.csv")
52+
body = get_target_response["Body"].read().decode("utf-8")
5353
assert body == "some CSV content"
5454

55+
with self.assertRaises(ClientError) as e:
56+
s3.head_object(Bucket="source-bucket", Key="test-csv-file.csv")
57+
self.assertEqual(e.exception.response["Error"]["Code"], "404")
58+
59+
head_archive_response = s3.head_object(Bucket="source-bucket", Key="archive/test-csv-file.csv")
60+
assert head_archive_response["ResponseMetadata"]["HTTPStatusCode"] == 200
61+
5562
def test_non_multipart_content_type_no_mesh_metadata(self):
5663
s3 = boto3.client("s3", region_name="eu-west-2")
5764
s3.put_object(

terraform/mesh_processor.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ resource "aws_iam_policy" "mesh_processor_lambda_exec_policy" {
137137
"s3:GetObject",
138138
"s3:ListBucket",
139139
"s3:PutObject",
140-
"s3:CopyObject"
140+
"s3:CopyObject",
141+
"s3:DeleteObject"
141142
]
142143
Resource = [
143144
aws_s3_bucket.batch_data_source_bucket.arn,

0 commit comments

Comments
 (0)