Skip to content

Commit 7b45a02

Browse files
committed
v1.1.1 - Bug Fixes
1 parent ddd7190 commit 7b45a02

3 files changed

Lines changed: 34 additions & 24 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## 1.1.1 - 2024-10-25
6+
### Bug Fixes
7+
- Fixed a typo on the CDK Stack preventing new deployments.
8+
- Fixed an issue with the `sync_files` lambda function while comparing timestamps. For now the `safe_time_compare` feature is disabled until a better method can be implemented.
9+
510
## 1.1.0 - 2024-10-25
611
### Added features
712
- Added the ability to define an optional KMS Key for the target buckets in the configuration files. This allows you to set up a default encryption with KMS on the target buckets.

transfer_sync_service/lambda/sync_files/sync_files.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -164,28 +164,32 @@ def should_transfer_file(file: Dict[str, Any], first_copy: bool, safe_time_compa
164164
# If it's the first copy, transfer all files
165165
if first_copy:
166166
return True
167+
168+
#############################################################################################################################
169+
## Need to implement a better safe_time_compare method to avoid cost duplication. Disabled for now. ##
170+
## Only data updated in source SFTP between previous execution and S3 Object timestamp should be copied. ##
171+
## Also need to add a feature flag to allow the user to decide if deleted files in target S3 Bucket needs to be re-copied. ##
172+
#############################################################################################################################
167173

168174
# For subsequent copies, check if the file is new or modified
169-
if safe_time_compare < file_time:
170-
try:
171-
# Check if the file exists in the destination and compare modification times
172-
obj = s3.head_object(
173-
Bucket=event['SyncSetting']['LocalRepository']['BucketName'],
174-
Key=f"{event['SyncSetting']['LocalRepository']['Prefix']}{file['filePath']}"
175-
)
176-
if obj['LastModified'] < file_time:
177-
logger.info(f"File {file['filePath']} has been modified since last copy.")
178-
return True
179-
else:
180-
logger.info(f"File {file['filePath']} has not been modified since last copy.")
181-
return False
182-
except botocore.exceptions.ClientError:
183-
# If the file doesn't exist in the destination, it should be transferred
184-
logger.info(f"File {file['filePath']} has not been copied before.")
175+
try:
176+
# Check if the file exists in the destination and compare modification times
177+
obj = s3.head_object(
178+
Bucket=event['SyncSetting']['LocalRepository']['BucketName'],
179+
Key=f"{event['SyncSetting']['LocalRepository']['Prefix']}{file['filePath']}"
180+
)
181+
if obj['LastModified'] < file_time:
182+
logger.info(f"File {file['filePath']} has been modified since last copy.")
185183
return True
186-
else:
187-
logger.info(f"File {file['filePath']} is not new.")
188-
return False
184+
# elif obj['LastModified'] >= safe_time_compare:
185+
# logger.info(f"File {file['filePath']} has been modified since safe time.")
186+
else:
187+
logger.info(f"File {file['filePath']} has not been modified since last copy.")
188+
return False
189+
except botocore.exceptions.ClientError:
190+
# If the file doesn't exist in the destination, it should be transferred
191+
logger.info(f"File {file['filePath']} has not been copied before.")
192+
return True
189193

190194
def transfer_files(file_list: List[str], event: Dict[str, Any]) -> None:
191195
"""
@@ -252,10 +256,10 @@ def calculate_safe_time_compare(schedule: str, start_time: datetime) -> datetime
252256
interval = (next_times[1] - next_times[0]).total_seconds() / 60 # in minutes
253257

254258
if 1 <= interval <= 5:
255-
n = 5
256-
elif 5 < interval <= 60:
259+
n = 3
260+
elif 5 < interval <= 10:
257261
n = 2
258-
elif 60 < interval <= 1440: # 24 hours
262+
elif 10 < interval <= 60:
259263
n = 1
260264
else:
261265
n = 0

transfer_sync_service/transfer_sync_service_stack.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def install_package(package, target):
5959
if not os.path.exists('transfer_sync_service/lambda/sync_files/pyawscron'):
6060
print('Installing some dependencies for Lambda')
6161
install_package(
62-
f'pyawscron~={solution_parameters['pyawscron_version']}',
62+
f'pyawscron~={solution_parameters["pyawscron_version"]}',
6363
'transfer_sync_service/lambda/sync_files/'
6464
)
6565

@@ -293,7 +293,7 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
293293
monitoring.add_large_header('Transfer Family Connectors')
294294

295295
# Process configuration files
296-
for file in self.files('./configuration/sftp/'):
296+
for file in self.files('./configuration/sftp/'):
297297
with open(f'./configuration/sftp/{file}', encoding='utf8') as service_config:
298298
config = json.load(service_config)
299299
print(f'Creating resources for {config["Name"]}...')
@@ -370,6 +370,7 @@ def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
370370
iam.PolicyStatement(
371371
actions=[
372372
's3:GetObjectAttributes',
373+
's3:GetObject',
373374
's3:PutObject',
374375
's3:PutObjectACL'
375376
],

0 commit comments

Comments
 (0)