Configure Boto3 endpoint_url
Posted 5 August 2023
Being able to configure the Boto3 endpoint_url
with an environment variable is a long awaited feature added in boto3 1.28.0
.
When developing an application that uses AWS services a common approach is to use local services during development, such as those provided by LocalStack.
AWS SDK now supports configuring service specific endpoints through AWS_ENDPOINT_URL
and AWS_ENDPOINT_URL_<SERVICE>
environment variables.
With the following env variables:
AWS_ENDPOINT_URL=http://localhost:4566
AWS_ENDPOINT_URL_S3=http://localhost:4567
Boto3 will use these values to set the endpoint_url
:
import boto3
db = boto3.client("dynamodb") # endpoint_url=http://localhost:4566
s3 = boto3.client("s3") # endpoint_url=http://localhost:4567