Random S3 Bucket Name Generator

  • Share this:

Code introduction


This function generates a random S3 bucket name using a given prefix and length to create a unique bucket name.


Technology Stack : boto3, random, string

Code Type : Function

Code Difficulty : Intermediate


                
                    
def generate_random_s3_bucket_name(prefix, length=10):
    import random
    import string

    characters = string.ascii_lowercase + string.digits
    return f"{prefix}-{random.choices(characters, k=length).join('')}"