简体   繁体   中英

How do you specify region for AWS SDK for Python boto3

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 ?

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='/')

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM