David A Good

How to Connect to DynamoDB Local Using the AWS SDK for Go

August 27, 2021

Example code demonstrating how to connect to locally running DynamoDB such as DynamoDB Local or LocalStack.

By the way, you can run DynamoDB Local very easily like this:

docker run -p 8000:8000 amazon/dynamodb-local

Note: This code uses the AWS SDK Go v2.

import (

func CreateLocalClient() *dynamodb.Client {
	cfg, err := config.LoadDefaultConfig(context.TODO(),
			func(service, region string) (aws.Endpoint, error) {
				return aws.Endpoint{URL: "http://localhost:8000"}, nil
			Value: aws.Credentials{
				AccessKeyID: "dummy", SecretAccessKey: "dummy", SessionToken: "dummy",
				Source: "Hard-coded credentials; values are irrelevant for local DynamoDB",
	if err != nil {

	return dynamodb.NewFromConfig(cfg)

See full code on GitHub which also has examples of:

  • Paginated, full-table Scan using ExclusiveStartKey
  • CreateTable but only if the table does not already exist
  • Conditional check to prevent overwriting an existing item with a PutItem operation
  • Logic to check if an SDK error is due to a condition check failure (ConditionalCheckFailed)

One more bonus: There are many more examples of configuring the client here, aws-sdk-go-v2/config/example_test.go

Software engineer crafting full-stack, cloud-native solutions for enterprise. GitHub | LinkedIn | Twitter