Skip to content

Instantly share code, notes, and snippets.

@bahrmichael
Last active January 5, 2021 17:53
Show Gist options
  • Save bahrmichael/57c6660a634e30127b6d14681b6cd62c to your computer and use it in GitHub Desktop.
Save bahrmichael/57c6660a634e30127b6d14681b6cd62c to your computer and use it in GitHub Desktop.
import boto3
from uuid import uuid4
import random
client = boto3.client('s3')
bucket_name = 'my-bucket-name'
categories = ['a', 'b', 'c']
for i in range(50):
key = str(uuid4())
category = random.choice(categories)
client.put_object(Body=str(i).encode(), Bucket=bucket_name, Key=f"{category}/{key}")
print(f"Inserted {key} for category {category}")
list_response = client.list_objects_v2(
Bucket=bucket_name,
)
for c in list_response['Contents']:
print(c['Key'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment