Skip to content

Instantly share code, notes, and snippets.

@linjungz
Created December 11, 2020 16:55
Show Gist options
  • Save linjungz/b0123caaeb08bb70b445f18f78cd9432 to your computer and use it in GitHub Desktop.
Save linjungz/b0123caaeb08bb70b445f18f78cd9432 to your computer and use it in GitHub Desktop.
Simple demo for creating S3 pre-signed url in Lambda
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