Configure Boto3 endpoint_url

Posted 5 August 2023 · 1 min read

Tags:

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

Get new posts by email

Subscribe to get new posts to your inbox, or use the RSS feed with your own feed reader.


Related posts · browse by tag

Mocking Boto3 with pytest

Published · 1 min read

Mock requests to AWS services with pytest

Python TypedDict with Generics

Published · 1 min read

How to define a Python type for a dict with generic values

Using TypedDict with invalid attribute names

Published · 1 min read

How to use a TypedDict with item keys that aren't valid identifiers