1

I am trying to get multiple objects from an S3 bucket using python with aws cli installed and configure. I can currently get a single file using this code.

import boto3


url = boto3.client('s3').generate_presigned_url(
ClientMethod='get_object', 
Params={'Bucket': 'test-bucket', 'Key':'00001.png'},
ExpiresIn=3600)

print(url)

However I need to generate the same for 100 other image files, how can I possibly do this?

Jowey
  • 61
  • 4
  • 1
    I think this could be useful: https://stackoverflow.com/questions/36344194/pre-signed-url-for-multiple-files/67830706#67830706 – OARP Jan 14 '22 at 14:47

1 Answers1

0

Run the code 100 times -- seriously!

You should separate out the client generation, such as:

s3_client = boto3.client('s3')

url = s3_client.generate_presigned_url(...)

It's a very quick command and doesn't require a call to AWS so you can repeat or loop-through the last line many times.

Each object will require a separate pre-signed URL because permission is being generated for just one object at a time.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470