Home > Software engineering >  How do you specify region for aws python boto3 list_objects_v2?
How do you specify region for aws python boto3 list_objects_v2?

Time:05-29

From cli I can execute the command: aws s3api list-objects –-bucket BUCKETNAME -—region REGIONAME

How do I equivalently specify the region for botocore3 list_objects_v2?

CodePudding user response:

It can be added while setting params

s3_client = boto3.client(
             's3',
             aws_access_key_id='access_key_here',
             aws_secret_access_key='access_key_secret_here',
             config=boto3.session.Config(signature_version='s3v4'),
             region_name='region_here'
            )

Then your request to get object lists:

response = s3_client.list_objects_v2(Bucket=bucket_name, Prefix='', Delimiter='/')

CodePudding user response:

In the Python Docs there are a lot of examples of how to do this. WHen you set a Service Client using the AWS SDK, all languages let you set a region. The AWS SDK for Python is no different.

Here is a code example that shows you how to set the region when creating a Service Client.

import boto3
from botocore.config import Config

proxy_definitions = {
    'http': 'http://proxy.amazon.com:6502',
    'https': 'https://proxy.amazon.org:2010'
}

my_config = Config(
    region_name='us-east-2',
    signature_version='v4',
    proxies=proxy_definitions,
    proxies_config={
        'proxy_client_cert': '/path/of/certificate'
    }
)

client = boto3.client('kinesis', config=my_config)

More information can be found here:

https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html#guide-configuration

  • Related