Skip to content

Commit 4b17d6e

Browse files
[PRMT-17] S3 Intelligent-Tiering (#620)
1 parent 18b8f1d commit 4b17d6e

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

lambdas/services/base/s3_service.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def copy_across_bucket(
9999
Bucket=dest_bucket,
100100
Key=dest_file_key,
101101
CopySource={"Bucket": source_bucket, "Key": source_file_key},
102+
StorageClass="INTELLIGENT_TIERING",
102103
)
103104

104105
def delete_object(self, s3_bucket_name: str, file_key: str):

lambdas/tests/unit/services/base/test_s3_service.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ def test_copy_across_bucket(mock_service, mock_client):
129129
Bucket="bucket_to_copy_to",
130130
Key=f"{TEST_NHS_NUMBER}/{TEST_UUID}",
131131
CopySource={"Bucket": "bucket_to_copy_from", "Key": TEST_FILE_KEY},
132+
StorageClass="INTELLIGENT_TIERING",
132133
)
133134

134135

tests/bulk-upload/scripts/setup_bulk_upload.py

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import argparse
12
import csv
23
import os
34
import shutil
5+
from datetime import date
46
from enum import StrEnum
57
from glob import glob
6-
from typing import List, Dict, NamedTuple, Any
7-
from datetime import date
8-
import argparse
8+
from typing import Any, Dict, List, NamedTuple
99

1010
import boto3
1111
from botocore.exceptions import ClientError
@@ -196,25 +196,37 @@ def flatten(input_list: List[List[Any]]) -> List[Any]:
196196
def build_valid_lg_file_name(
197197
patient: Patient, file_count: int = 1, total_number: int = 3
198198
) -> str:
199-
return f"{file_count}of{total_number}_Lloyd_George_Record_[{patient.full_name}]_[{patient.nhs_number}]_[{patient.date_of_birth}].pdf"
199+
return (
200+
f"{file_count}of{total_number}_Lloyd_George_Record_["
201+
f"{patient.full_name}]_[{patient.nhs_number}]_[{patient.date_of_birth}].pdf"
202+
)
200203

201204

202205
def build_invalid_lg_file_name(
203206
patient: Patient, file_count: int = 1, total_number: int = 3
204207
) -> str:
205-
return f"{file_count}of{total_number}_Lloyd_George_Record_[{patient.nhs_number}]_[{patient.full_name}]_[{patient.date_of_birth}].pdf"
208+
return (
209+
f"{file_count}of{total_number}_Lloyd_George_Record_["
210+
f"{patient.nhs_number}]_[{patient.full_name}]_[{patient.date_of_birth}].pdf"
211+
)
206212

207213

208214
def build_invalid_file_number_lg_file_name(
209215
patient: Patient, file_count: int = 1, total_number: int = 3
210216
) -> str:
211-
return f"{file_count}of{total_number - 1}_Lloyd_George_Record[{patient.full_name}]_[{patient.nhs_number}]_[{patient.date_of_birth}].pdf"
217+
return (
218+
f"{file_count}of{total_number - 1}_Lloyd_George_Record["
219+
f"{patient.full_name}]_[{patient.nhs_number}]_[{patient.date_of_birth}].pdf"
220+
)
212221

213222

214223
def build_invalid_nhs_number_lg_file_name(
215224
patient: Patient, file_count: int = 1, total_number: int = 3
216225
) -> str:
217-
return f"{file_count}of{total_number}_Lloyd_George_Record_[{patient.full_name}]_[{str(patient.nhs_number)[:-2]}01]_[{patient.date_of_birth}].pdf"
226+
return (
227+
f"{file_count}of{total_number}_Lloyd_George_Record_["
228+
f"{patient.full_name}]_[{str(patient.nhs_number)[:-2]}01]_[{patient.date_of_birth}].pdf"
229+
)
218230

219231

220232
def build_many_file_names(patient: Patient, total_number: int = 3) -> List[str]:
@@ -305,7 +317,10 @@ def build_metadata_csv_rows(patient: Patient, total_number: int = 3) -> list[str
305317
def build_metadata_csv(
306318
patient_list: List[Patient], total_number_for_each: int = 3
307319
) -> str:
308-
header_row = "FILEPATH,PAGE COUNT,GP-PRACTICE-CODE,NHS-NO,SECTION,SUB-SECTION,SCAN-DATE,SCAN-ID,USER-ID,UPLOAD"
320+
header_row = (
321+
"FILEPATH,PAGE COUNT,GP-PRACTICE-CODE,NHS-NO,"
322+
"SECTION,SUB-SECTION,SCAN-DATE,SCAN-ID,USER-ID,UPLOAD"
323+
)
309324
all_rows = []
310325
for patient in patient_list:
311326
row = build_metadata_csv_rows(
@@ -374,7 +389,12 @@ def upload_lg_files_to_staging():
374389
files = ["metadata.csv"] + glob("*/*Lloyd_George_Record*.pdf")
375390
client = boto3.client("s3")
376391
for file in files:
377-
client.upload_file(Filename=file, Bucket=STAGING_BUCKET, Key=file)
392+
client.upload_file(
393+
Filename=file,
394+
Bucket=STAGING_BUCKET,
395+
Key=file,
396+
ExtraArgs={"StorageClass": "INTELLIGENT_TIERING"},
397+
)
378398

379399
scan_result = "Clean"
380400
if file.startswith(tuple(NHS_NUMBER_INFECTED)):
@@ -580,15 +600,17 @@ def get_user_input():
580600
if (
581601
args.upload
582602
or input(
583-
"Would you like to upload the test files to S3 and add the virus-scan tag? (y/N) "
603+
"Would you like to upload the test files to S3 "
604+
"and add the virus-scan tag? (y/N) "
584605
).lower()
585606
== "y"
586607
):
587608
upload_lg_files_to_staging()
588609
if (
589610
args.empty_lloydgeorge_store
590611
or input(
591-
"Would you like to remove all records from the LloydGeorgeRecord Bucket (y/N) "
612+
"Would you like to remove all records "
613+
"from the LloydGeorgeRecord Bucket (y/N) "
592614
).lower()
593615
== "y"
594616
):

0 commit comments

Comments
 (0)