如何获取 python 包 `awswranger` 以接受自定义的 `endpoint_url`

How to get python package `awswranger` to accept a custom `endpoint_url`

我正在尝试使用 python 程序包 awswrangler 访问非 AWS S3 服务。

AWS Data Wranger docs 声明您需要创建一个 boto3.Session() 对象。

问题是 boto3.client() 支持设置 endpoint_url,但 boto3.Session() 不支持 (docs here)

在我之前使用 boto3 时,出于这个原因,我一直使用 client

有没有办法用自定义 endpoint_url 创建 boto3.Session() 或配置 awswrangler 以接受自定义端点?

创建会话后,您也可以使用 client。例如:

import boto3

session = boto3.Session()
s3 = session.client('s3', endpoint_url='<custom-endpoint>')

我终于找到了 awswrangler 的配置:

import awswrangler as wr

wr.config.s3_endpoint_url = 'https://custom.endpoint'

Any configuration variables for awswrangler can be overwritten directly using the wr.config config object as you stated in your answer, but it may be cleaner or preferable in some use cases to use environment variables.

在这种情况下,只需将 WR_S3_ENDPOINT_URL 设置为您的自定义端点,配置就会在您导入库时反映出来。