read first file returned from s3

rather than looping through, just use `next`. We only expect to return
one file, so this won't actually affect the code flow. If, for whatever
reason, the file isn't on s3, whereas previously it would error when
trying to return an uninstantiated variable, now it will raise a
StopIteration
This commit is contained in:
Leo Hemsted
2018-08-08 17:21:16 +01:00
parent 62d70dbd4d
commit 1ff729e75f

View File

@@ -135,14 +135,15 @@ def get_letter_pdf(notification):
s3 = boto3.resource('s3')
bucket = s3.Bucket(bucket_name)
for item in bucket.objects.filter(Prefix=get_bucket_prefix_for_notification(notification, is_test_letter)):
obj = s3.Object(
bucket_name=bucket_name,
key=item.key
)
file_content = obj.get()["Body"].read()
item = next(x for x in bucket.objects.filter(
Prefix=get_bucket_prefix_for_notification(notification, is_test_letter)
))
return file_content
obj = s3.Object(
bucket_name=bucket_name,
key=item.key
)
return obj.get()["Body"].read()
def _move_s3_object(source_bucket, source_filename, target_bucket, target_filename):