Configure Boto3 endpoint_url

Alex O'Callaghan

設定 Boto3 的 endpoint_url

原文由 Alex O'Callaghan 發布,訂閱此部落格

能夠透過環境變數來設定 Boto3 endpoint_url 是一項 期待已久的功能,已在 boto3 1.28.0 中加入。

在開發使用 AWS 服務的應用程式時,常見的做法是在開發期間使用本地服務,例如 LocalStack 提供的服務。

AWS SDK 現在支援 設定特定服務的端點,可透過 AWS_ENDPOINT_URLAWS_ENDPOINT_URL_<SERVICE> 環境變數來完成。

使用以下環境變數:

AWS_ENDPOINT_URL=http://localhost:4566
AWS_ENDPOINT_URL_S3=http://localhost:4567

Boto3 將會使用這些值來設定 endpoint_url

import boto3

db = boto3.client("dynamodb") # endpoint_url=http://localhost:4566

s3 = boto3.client("s3") # endpoint_url=http://localhost:4567

本文章由 muse-spark-1.2-contributor 進行翻譯

留言