Dawny33
Dawny33

Reputation: 11081

How do I get an object from S3 using it's pre-signed url in boto3?

I have generated a pre-signed url for an object in one of my buckets using boto3:

s3.generate_presigned_url('get_object', Params = {'Bucket': 'https://s3.amazonaws.com/<>', 'Key': '<>.json'}, ExpiresIn = 100)

Now, how do I get_object it in boto3? The boto3's get_object reference doesn't specify any argument for a pre-signed url.

So, how do I get that object from S3 using it's pre-signed url in boto3?

Upvotes: 6

Views: 4999

Answers (2)

Santosh kumar Manda
Santosh kumar Manda

Reputation: 614

you can use this code to get the result.

import boto3
s3_client = boto3.client('s3')
resp = s3_client.generate_presigned_url('get_object', Params = {'Bucket': 'your-s3-bucket', 'Key': 'filepath/inside-bucket/filename.json'}, ExpiresIn = 100)
print(resp)

if any doubt please let me know.

Upvotes: 3

Michael - sqlbot
Michael - sqlbot

Reputation: 179084

If you have a pre-signed URL, you don't need boto -- you can download the object using any HTTP user agent library.

Conversely, if you have boto and the credentials, you don't need a pre-signed URL.

Pre-signed URLs are intended for allowing someone with credentials to enable someone else without credentials to access a resource, without exposing the credentials to them.

A pre-signed URL includes the access-key-id and possibly a session-token, but not the access-key-secret, and are computationally-infeasible to reverse-engineer... and in this sense, they do not expose the credentials in a way that allows the entity possessing the pre-signed URL to use the associated credentials for any other purpose.

Upvotes: 5

Related Questions