ЛР5 — БВТ2302 — Никитина — на 5
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import boto3
|
||||
from botocore.client import Config
|
||||
import os
|
||||
import time
|
||||
|
||||
endpoint = os.environ.get("S3_ENDPOINT", "http://minio:9000")
|
||||
access_key = os.environ.get("S3_ACCESS_KEY", "minioadmin")
|
||||
secret_key = os.environ.get("S3_SECRET_KEY", "minioadmin")
|
||||
bucket = os.environ.get("S3_BUCKET", "attachments")
|
||||
|
||||
s3 = boto3.client(
|
||||
"s3",
|
||||
endpoint_url=endpoint,
|
||||
aws_access_key_id=access_key,
|
||||
aws_secret_access_key=secret_key,
|
||||
config=Config(signature_version="s3v4"),
|
||||
region_name="us-east-1"
|
||||
)
|
||||
|
||||
print(f"Connecting to MinIO at {endpoint}...")
|
||||
for i in range(10):
|
||||
try:
|
||||
s3.head_bucket(Bucket=bucket)
|
||||
print(f"Bucket '{bucket}' already exists.")
|
||||
break
|
||||
except Exception:
|
||||
try:
|
||||
s3.create_bucket(Bucket=bucket)
|
||||
print(f"Bucket '{bucket}' created successfully.")
|
||||
break
|
||||
except Exception as e:
|
||||
print(f"Waiting for MinIO to start... ({e})")
|
||||
time.sleep(2)
|
||||
Reference in New Issue
Block a user