55import boto3
66from smart_open import open
77
8- from common .clients import s3_client
8+ from common .clients import get_s3_client
99
1010EXPECTED_BUCKET_OWNER_ACCOUNT = os .getenv ("ACCOUNT_ID" )
1111DESTINATION_BUCKET_NAME = os .getenv ("DESTINATION_BUCKET_NAME" )
@@ -71,22 +71,22 @@ def stream_part_body(input_file: BinaryIO, boundary: bytes, output_file: BinaryI
7171
7272
7373def move_file (source_bucket : str , source_key : str , destination_bucket : str , destination_key : str ) -> None :
74- s3_client .copy_object (
74+ get_s3_client () .copy_object (
7575 CopySource = {"Bucket" : source_bucket , "Key" : source_key },
7676 Bucket = destination_bucket ,
7777 Key = destination_key ,
7878 ExpectedBucketOwner = EXPECTED_BUCKET_OWNER_ACCOUNT ,
7979 ExpectedSourceBucketOwner = EXPECTED_BUCKET_OWNER_ACCOUNT ,
8080 )
81- s3_client .delete_object (
81+ get_s3_client () .delete_object (
8282 Bucket = source_bucket ,
8383 Key = source_key ,
8484 ExpectedBucketOwner = EXPECTED_BUCKET_OWNER_ACCOUNT ,
8585 )
8686
8787
8888def transfer_multipart_content (bucket_name : str , file_key : str , boundary : bytes , filename : str ) -> None :
89- with open (f"s3://{ bucket_name } /{ file_key } " , "rb" , transport_params = {"client" : s3_client }) as input_file :
89+ with open (f"s3://{ bucket_name } /{ file_key } " , "rb" , transport_params = {"client" : get_s3_client () }) as input_file :
9090 read_until_part_start (input_file , boundary )
9191
9292 headers = read_part_headers (input_file )
@@ -100,7 +100,7 @@ def transfer_multipart_content(bucket_name: str, file_key: str, boundary: bytes,
100100 f"s3://{ DESTINATION_BUCKET_NAME } /streaming/{ filename } " ,
101101 "wb" ,
102102 transport_params = {
103- "client" : s3_client ,
103+ "client" : get_s3_client () ,
104104 "client_kwargs" : {"S3.Client.create_multipart_upload" : {"ContentType" : content_type }},
105105 },
106106 ) as output_file :
@@ -119,7 +119,7 @@ def process_record(record: dict) -> None:
119119 file_key = record ["s3" ]["object" ]["key" ]
120120 logger .info (f"Processing { file_key } " )
121121
122- response = s3_client .head_object (
122+ response = get_s3_client () .head_object (
123123 Bucket = bucket_name ,
124124 Key = file_key ,
125125 ExpectedBucketOwner = EXPECTED_BUCKET_OWNER_ACCOUNT ,
@@ -134,7 +134,7 @@ def process_record(record: dict) -> None:
134134 boundary = content_type_params ["boundary" ].encode ("utf-8" )
135135 transfer_multipart_content (bucket_name , file_key , boundary , filename )
136136 else :
137- s3_client .copy_object (
137+ get_s3_client () .copy_object (
138138 Bucket = DESTINATION_BUCKET_NAME ,
139139 CopySource = {"Bucket" : bucket_name , "Key" : file_key },
140140 Key = filename ,
0 commit comments