generated from cepdnaclk/eYY-3yp-project-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
22ae030
commit 67b0070
Showing
1 changed file
with
14 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,27 @@ | ||
import json | ||
import boto3 | ||
import base64 | ||
from botocore.exceptions import ClientError | ||
|
||
client=boto3.client('s3') | ||
|
||
def lambda_handler(event, context): | ||
print(event) | ||
|
||
bucket_name='arcombat-qr' | ||
body_dict = json.loads(event['body']) | ||
image_file_name=body_dict['email'] | ||
|
||
response = client.get_object( | ||
Bucket=bucket_name, | ||
Key=image_file_name+'.png', | ||
) | ||
image_file_to_be_downloaded=response['Body'].read() | ||
|
||
try: | ||
response = client.generate_presigned_url('get_object', | ||
Params={'Bucket': bucket_name, | ||
'Key': image_file_name+'.png'}, | ||
ExpiresIn=18000) | ||
except ClientError as e: | ||
logging.error(e) | ||
return None | ||
|
||
return { | ||
'statusCode': 200, | ||
'body':base64.b64encode(image_file_to_be_downloaded) , | ||
'isBase64Encoded': True | ||
'body': json.dumps({'presigned_url': response}), | ||
} |