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

Related posts

Mocking Boto3 with pytest

Published

Mock requests to AWS services with pytest

Python TypedDict with Generics

Published

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

Using TypedDict with invalid attribute names

Published

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


Thanks for reading

I'm Alex O'Callaghan and this is my personal website where I write about software development and do my best to learn in public. I currently work at Mintel as a Principal Engineer working primarily with React, TypeScript & Python.

I've been leading one of our platform teams maintaining a collection of shared libraries, services and a micro-frontend architecture.

I'm from London and you can find me on a few different social media platforms: