Python Boto3

How to use the Boto3 Python AWS SDK with LocalStack.

Boto3 is the Amazon Web Services (AWS) Software Development Kit (SDK) for Python, which allows Python developers to write software that makes use of AWS services.

You can easily create a boto3 client that interacts with your LocalStack instance. The example below creates a boto3 client that lists all available Lambda functions:

import boto3

endpoint_url = ""
# alternatively, to use HTTPS endpoint on port 443:
# endpoint_url = ""

def main():
    client = boto3.client("lambda", endpoint_url=endpoint_url)
    result = client.list_functions()

if __name__ == "__main__":
client = boto3.client("lambda")

Alternatively, if you prefer to (or need to) set the endpoints directly, you can use the environment variable AWS_ENDPOINT_URL, which is available when executing user code (e.g., Lambda functions) in LocalStack:

import os
client = boto3.client("lambda", endpoint_url=os.getenv("AWS_ENDPOINT_URL"))

Further Material: