Last active
September 15, 2020 19:28
-
-
Save nmagee/0f3a2ff3c70f8fb4e533976b8416cb72 to your computer and use it in GitHub Desktop.
Presign a URL in S3 using boto3
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
| #!/usr/local/bin/python3 | |
| # To use this snippet: | |
| # Create a bucket and upload a private file into it beforehand. | |
| # To make the private file shareable for a fixed number of seconds | |
| # you can "presign" the URL, which creates an expiring hashed URL. | |
| # You can then distribute that URL to other systems or coleagues. | |
| import boto3 | |
| bucket = "BUCKET_NAME" # replace with actual bucket name | |
| file_path = "FILE_PATH" # could be "file.txt" or "path/folder/file.txt" | |
| timeout = 30 | |
| client = boto3.client('s3') | |
| args = { | |
| 'ClientMethod': 'get_object', | |
| 'Params': { 'Bucket': bucket, 'Key': file_path }, | |
| 'ExpiresIn': timeout | |
| } | |
| response = client.generate_presigned_url(**args); | |
| print(response) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment