Skip to content

Commit

Permalink
Fix/s3 iam add region name (#7819)
Browse files Browse the repository at this point in the history
  • Loading branch information
GarfieldDai authored Oct 12, 2024
1 parent 23ce1fb commit c6b74da
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion api/extensions/storage/aws_s3_storage.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from collections.abc import Generator
from contextlib import closing

Expand All @@ -8,6 +9,8 @@

from extensions.storage.base_storage import BaseStorage

logger = logging.getLogger(__name__)


class AwsS3Storage(BaseStorage):
"""Implementation for Amazon Web Services S3 storage."""
Expand All @@ -17,9 +20,14 @@ def __init__(self, app: Flask):
app_config = self.app.config
self.bucket_name = app_config.get("S3_BUCKET_NAME")
if app_config.get("S3_USE_AWS_MANAGED_IAM"):
logger.info("Using AWS managed IAM role for S3")

session = boto3.Session()
self.client = session.client("s3")
region_name = app_config.get("S3_REGION")
self.client = session.client(service_name="s3", region_name=region_name)
else:
logger.info("Using ak and sk for S3")

self.client = boto3.client(
"s3",
aws_secret_access_key=app_config.get("S3_SECRET_KEY"),
Expand Down

0 comments on commit c6b74da

Please sign in to comment.