Created
June 6, 2020 20:04
-
-
Save DoguD/6fc9fe792b8a2f11e0e5a50c1bf8d4ca to your computer and use it in GitHub Desktop.
Chalice code for getting presigned S3 URL>
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
| from chalice import Chalice | |
| import boto3 | |
| import json | |
| app = Chalice(app_name='s3_presigned_file_upload') | |
| BUCKET_NAME = '<INSERT_BUCKET_NAME_HERE>' | |
| REGION = '<INSERT_REGION_HERE>' | |
| @app.route('/generate_presigned_url', methods=['GET'], cors=True) | |
| def generate_presigned_url(): | |
| parameters = app.current_request.query_params | |
| file_name = parameters['file_name'] | |
| s3_client = boto3.client("s3", region_name=REGION) | |
| fields = s3_client.generate_presigned_url('put_object', | |
| Params={'Bucket': BUCKET_NAME, | |
| 'Key': file_name, | |
| 'ACL': 'public-read' | |
| }, | |
| ExpiresIn=3600) | |
| return json.dumps({'status': 'OK', 'fields': fields}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment