Generate AWS-S3 signed (time-limited) URLs in Python

Generate AWS-S3 signed (time-limited) URLs in Python

Introduction

`Although it is an article on Mac environment, the procedure is the same for Windows environment. Please read and try the environment-dependent part. ``

Purpose

After reading this article to the end, you will be able to:

No. Overview keyword
1 Signed URL generation s3, generate_presigned_url

Execution environment

environment Ver.
macOS Catalina 10.15.3
Python 3.7.3
boto3 1.11.17

Source code

I think that understanding will deepen if you read while actually following the implementation contents and source code. Please use it by all means.

GitHub

Related articles

Generate signed URL

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

Generate AWS-S3 signed (time-limited) URLs in Python
Generate rounded thumbnails in Python
Generate U distribution in Python
Generate QR code in Python
Generate 8 * 8 (64) cubes in Blender Python
[Python] Generate QR code in memory
Generate Jupyter notebook ".ipynb" in Python
[GCP] How to publish Cloud Storage signed URLs (temporary URLs) in Python
Generate a first class collection in Python
Automatically generate Python Docstring Comment in Emacs
Module to generate word N-gram in Python
Generate a class from a string in Python
Generate C language from S-expressions in Python
Convert absolute URLs to relative URLs in Python
Generate the Look-and-say Sequence featured in QuizKnock in Python
Quadtree in Python --2
CURL in python
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
How to generate permutations in Python and C ++
Meta-analysis in Python
Unittest in python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
N-Gram in Python
Programming in python
[Cloudian # 10] Try to generate a signed URL for object publishing in Python (boto3)
Plink in Python
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
Load images from URLs using Pillow in Python 3
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Constant in python
nCr in Python.
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Issue the Amazon CloudFront Signed URL in Python
Quad-tree in Python
Generate points only in Tokyo using python + shapely
Reflection in Python
Chemistry in Python
Hashable in python
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python