Files
2026-11-19 15:03:52 +03:00

29 lines
880 B
Python

import os
import boto3
from botocore.client import Config
S3_ENDPOINT = os.getenv("S3_ENDPOINT", "http://s3:8333")
S3_BUCKET = os.getenv("S3_BUCKET", "messenger-attachments")
S3_ROOT_ACCESS_KEY = os.getenv("S3_ROOT_ACCESS_KEY", "minioadmin")
S3_ROOT_SECRET_KEY = os.getenv("S3_ROOT_SECRET_KEY", "minioadminpassword")
s3_client = boto3.client(
"s3",
endpoint_url=S3_ENDPOINT,
aws_access_key_id=S3_ROOT_ACCESS_KEY,
aws_secret_access_key=S3_ROOT_SECRET_KEY,
config=Config(signature_version="s3v4"),
region_name="us-east-1"
)
def init_bucket():
print(f"Checking/Creating bucket: {S3_BUCKET}")
try:
s3_client.head_bucket(Bucket=S3_BUCKET)
print("Bucket already exists.")
except Exception:
s3_client.create_bucket(Bucket=S3_BUCKET)
print("Bucket successfully created.")
if __name__ == "__main__":
init_bucket()