This commit is contained in:
pampixz
2026-11-12 14:37:43 +03:00
parent ec540a1a72
commit 6a7f4ec7d4
17 changed files with 749 additions and 24 deletions
+25
View File
@@ -0,0 +1,25 @@
import os
import time
import boto3
from botocore.config import Config
client = boto3.client(
's3', endpoint_url=os.getenv('S3_ENDPOINT', 'http://s3:8333'),
region_name='us-east-1',
aws_access_key_id=os.environ['S3_ACCESS_KEY_ID'],
aws_secret_access_key=os.environ['S3_SECRET_ACCESS_KEY'],
config=Config(connect_timeout=3, read_timeout=5, retries={'max_attempts': 1}),
)
bucket = os.getenv('S3_BUCKET', 'messenger-attachments')
for attempt in range(60):
try:
buckets = [x['Name'] for x in client.list_buckets().get('Buckets', [])]
if bucket not in buckets:
client.create_bucket(Bucket=bucket)
print('Private S3 bucket ready:', bucket)
break
except Exception as exc:
print('Waiting for S3:', str(exc), flush=True)
if attempt == 59:
raise
time.sleep(2)