Created
December 11, 2020 16:55
-
-
Save linjungz/b0123caaeb08bb70b445f18f78cd9432 to your computer and use it in GitHub Desktop.
Simple demo for creating S3 pre-signed url in Lambda
This file contains hidden or 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
import json | |
import boto3 | |
from botocore.exceptions import ClientError | |
s3client = boto3.client('s3') | |
def lambda_handler(event, context): | |
bucket_name = 'linjungz-weride-test' | |
object_name = 'photos/test.jpg' | |
expiration = 120 | |
try: | |
response = s3client.generate_presigned_url('get_object', | |
Params={'Bucket': bucket_name, | |
'Key': object_name}, | |
ExpiresIn=expiration) | |
except ClientError as e: | |
print(e) | |
return { | |
'statusCode': 500, | |
'body': 'Failed to generate url' | |
} | |
print(response) | |
return { | |
'statusCode': 200, | |
'body': 'Got URL: ' + response + '\n' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment