File tree Expand file tree Collapse file tree 1 file changed +13
-6
lines changed
Expand file tree Collapse file tree 1 file changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -46,18 +46,25 @@ def __init__(self):
4646 f"Initializing S3 client with bucket: { self .bucket_name } , region: { self .region } "
4747 )
4848
49- # Configure S3 client
50- config = Config (
51- signature_version = "s3v4" ,
52- region_name = self .region ,
49+ # a region-agnostic client (no region_name) always works for GetBucketLocation
50+ self .s3_client = boto3 .client (
51+ "s3" ,
52+ aws_access_key_id = self .access_key ,
53+ aws_secret_access_key = self .secret_key ,
54+ config = Config (signature_version = "s3v4" ),
5355 )
5456
57+ resp = self .s3_client .get_bucket_location (Bucket = self .bucket_name )
58+ self .bucket_region = resp ["LocationConstraint" ] or "us-east-1"
59+
60+ logging .info (f"Bucket region: { self .bucket_region } !" )
61+
5562 self .s3_client = boto3 .client (
5663 "s3" ,
57- # endpoint_url =self.endpoint_url ,
64+ region_name = self .bucket_region ,
5865 aws_access_key_id = self .access_key ,
5966 aws_secret_access_key = self .secret_key ,
60- config = config ,
67+ config = Config ( signature_version = "s3v4" ) ,
6168 )
6269
6370 # Ensure bucket exists
You can’t perform that action at this time.
0 commit comments