24 lines
757 B
Python
24 lines
757 B
Python
import boto3
|
|
import os
|
|
from botocore.client import Config
|
|
|
|
s3 = boto3.resource('s3',
|
|
endpoint_url='http://minio:9000',
|
|
aws_access_key_id='minioadmin',
|
|
aws_secret_access_key='minioadmin123',
|
|
config=Config(signature_version='s3v4'),
|
|
region_name='us-east-1')
|
|
|
|
buckets = ['media', 'static']
|
|
|
|
for bucket_name in buckets:
|
|
bucket = s3.Bucket(bucket_name)
|
|
try:
|
|
bucket.create()
|
|
print(f"Bucket '{bucket_name}' yaratildi.")
|
|
except Exception as e:
|
|
if "BucketAlreadyOwnedByYou" in str(e) or "BucketAlreadyExists" in str(e):
|
|
print(f"Bucket '{bucket_name}' allaqachon mavjud.")
|
|
else:
|
|
print(f"Xato: {e}")
|