`Although it is an article on Mac environment, the procedure is the same for Windows environment. Please read and try the environment-dependent part. ``
After reading this article to the end, you will be able to:
No. | Overview | keyword |
---|---|---|
1 | Signed URL generation | s3, generate_presigned_url |
environment | Ver. |
---|---|
macOS Catalina | 10.15.3 |
Python | 3.7.3 |
boto3 | 1.11.17 |
I think that understanding will deepen if you read while actually following the implementation contents and source code. Please use it by all means.
run.py
import os
import boto3
aws_access_key_id = os.getenv('AWS_ACCESS_KEY_ID', '')
aws_secret_access_key = os.getenv('AWS_SECRET_ACCESS_KEY', '')
region_name = os.getenv('REGION_NAME', '')
bucket = os.getenv('BUCKET', '')
key = os.getenv('KEY', '')
expires_in = os.getenv('EXPIRES_IN', '') # sec / 1hour = 3600sec.
def main():
s3 = boto3.client(
service_name='s3',
aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key,
region_name=region_name
)
presigned_url = s3.generate_presigned_url(
ClientMethod='get_object',
Params={
'Bucket': bucket,
'Key': key
},
ExpiresIn=expires_in,
HttpMethod='GET'
)
print('-----\n{}\n-----'.format(presigned_url))
if __name__ == '__main__':
main()
Recommended Posts