"""Bounded, authenticated S3 bucket bootstrap, without MinIO client images.""" import time from botocore.exceptions import ClientError from app.common import s3, bucket def main(): for attempt in range(60): try: client = s3() try: client.head_bucket(Bucket=bucket()) except ClientError as exc: if exc.response['Error']['Code'] not in ('404', 'NoSuchBucket', 'NotFound'): raise client.create_bucket(Bucket=bucket()) print('S3 bucket ready') return except Exception: if attempt == 59: raise SystemExit('S3 bootstrap failed; check storage configuration') from None time.sleep(2) if __name__ == '__main__': main()