2

My Bucket name 'ABC' has a structure as follows:

audiofiles
       audio_one.wav
       audio_two.mp3

I want a python code to get the URI of these files not the file or file list, the file uri so that I can use the file as the input link in the transcribe job.

  • Does this answer your question? [Quick way to list all files in Amazon S3 bucket?](https://stackoverflow.com/questions/3337912/quick-way-to-list-all-files-in-amazon-s3-bucket) – Dean Van Greunen Jan 19 '22 at 14:12

1 Answers1

1

The boto3 s3 client does not have a method to return the keys/files URLs.

But we can use the Public URL of each object:

import boto3

bucket_name = 'bucket_name'
s3 = boto3.resource('s3')


def lambda_handler(event, context):
    my_bucket = s3.Bucket(bucket_name)

    for obj in my_bucket.objects.all():
        url = f'https://{bucket_name}.s3.amazonaws.com/{obj.key}'
        print(url)

This will print something like this for you:

https://bucket_name.s3.amazonaws.com/audio_one.wav
https://bucket_name.s3.amazonaws.com/audio_two.mp3
https://bucket_name.s3.amazonaws.com/audio_three.mp3
valdeci
  • 13,962
  • 6
  • 55
  • 80