Localhost Endpoint to DynamoDB Local with Boto3 Localhost Endpoint to DynamoDB Local with Boto3 python python

Localhost Endpoint to DynamoDB Local with Boto3


It does support DynamoDB Local. You just need to set the appropriate endpoint such as you can do with other language SDKs

Here is a code snippet of how you can use boto3's client and resource interface via DynamoDB Local:

import boto3# For a Boto3 client.ddb = boto3.client('dynamodb', endpoint_url='http://localhost:8000')response = ddb.list_tables()print(response)# For a Boto3 service resourceddb = boto3.resource('dynamodb', endpoint_url='http://localhost:8000')print(list(ddb.tables.all()))


Note: You will want to extend the above response to include region. I have appended to Kyle's code above. If your initial attempt is greeted with a region error, this will return the appropriate '[]' response.

import boto3## For a Boto3 client ('client' is for low-level access to Dynamo service API)ddb1 = boto3.client('dynamodb', endpoint_url='http://localhost:8000', region_name='us-west-2')response = ddb1.list_tables()print(response)# For a Boto3 service resource ('resource' is for higher-level, abstracted access to Dynamo)ddb2 = boto3.resource('dynamodb', endpoint_url='http://localhost:8000', region_name='us-west-2')print(list(ddb2.tables.all()))


use dummy access key and id otherwise it will throw an exception on running the methods.

import boto3dynamodb = boto3.session('dynamodb',                          aws_access_key_id="anything",                          aws_secret_access_key="anything",                          region_name="us-west-2",                          endpoint_url="http://localhost:8000")