Home > Blockchain >  How to get the region of a boto3 S3 resource instance
How to get the region of a boto3 S3 resource instance

Time:08-06

I instantiate a boto3 S3 resource like this (code simplified):

import os
from pathlib import Path
import boto3


s3_resource = boto3.resource(
    "s3",
    aws_access_key_id=os.getenv("AWS_ACCESS_KEY_ID"),
    aws_secret_access_key=os.getenv("AWS_SECRET_ACCESS_KEY"),
    # NOTE: My config is:
        # [default]
        # region = eu-west-1
    region_name=os.getenv("region_name"),
)

How can I get the region to which the S3 resource is associated? Is there an attribute of the class / instance I can query?

I checked the enter image description here

EDIT: following your comment, maybe you're looking for get_bucket_location:

Returns the Region the bucket resides in.

  • Related