SL42
SL42

Reputation: 221

How to access data from presigned url(s) on S3 using boto3

I am fairly new to using AWS S3 and I am bit lost on how to extract data from a presigned url link. So currently, I was given the aws_access_key_id, aws_secret_access_key, and region_name. However, I am lost on how to extract the presigned url because I do see that the presigned url also has an AWS access key id, expiration time, .json, response-content-disposition,response-content-type, and Signature. I am also not sure what to put down as my key for the Params.

Other than that, when I do run the code(I provided an incorrect key), I am getting an InvalidRequest The authorization mechanism you have provided is not supported.

Example presigned url link:

https://video_annotations.s3.amazonaws.com/folder1/annotations/sub-folder1/9162dn28sd78n.json?respone-content-disposition=attachment$6B%50filename%9D812jad9.json&respone-content-type=application%3Fjson&AWSAccessKeyID=different_aws_access_key_id&Signature=pAKSR97&Expires=1661271906

This is what I currently have for my Code:

client = boto3.client(
   's3',
   aws_access_key_id = 'my_aws_access_key_id',
   aws_secret_access_key = 'my_aws_secret_access_key',
   region_name = 'my_region_name'
)

url = client.generate_presigned_url('get_object',
                                    Params={
                                        'Bucket':'video_annotations',
                                        'Key':'???',
                                    },
                                    ExpiresIn=1661271906)
print(url)

Any help would be greatly appreciated.

Upvotes: 1

Views: 1587

Answers (1)

Tony Yip
Tony Yip

Reputation: 750

The key is just the path of the object in bucket, for https://video_annotations.s3.amazonaws.com/folder1/annotations/sub-folder1/9162dn28sd78n.json?respone-content-disposition=attachment$6B%50filename%9D812jad9.json&respone-content-type=application%3Fjson&AWSAccessKeyID=different_aws_access_key_id&Signature=pAKSR97&Expires=1661271906, the key would be folder1/annotations/sub-folder1/9162dn28sd78n.json

Upvotes: 1

Related Questions