import time from app.main import s3, BUCKET for attempt in range(60): try: client = s3() if BUCKET not in [b['Name'] for b in client.list_buckets()['Buckets']]: client.create_bucket(Bucket=BUCKET) print('Private bucket ready') break except Exception: if attempt == 59: raise time.sleep(1)