dynobase-icon
Dynobase

Question: How do you mock DynamoDB in a test?

Rafal Wilinski

Answered by Rafal Wilinski

Last updated: October 23rd, 2026

Answer

Mock the SDK call used by your application, supply a controlled response, and assert the request as well as the application's result. A mock checks application behavior; it does not prove that a key schema or DynamoDB expression is valid.

With Python, botocore's Stubber can validate the expected request without sending it to AWS:

import boto3 from botocore.stub import Stubber client = boto3.client( "dynamodb", region_name="us-east-1", aws_access_key_id="testing", aws_secret_access_key="testing" ) def load_order(ddb, order_id): return ddb.get_item( TableName="Orders", Key={"pk": {"S": order_id}} ).get("Item") with Stubber(client) as stub: stub.add_response( "get_item", {"Item": {"pk": {"S": "ORDER#42"}}}, {"TableName": "Orders", "Key": {"pk": {"S": "ORDER#42"}}} ) assert load_order(client, "ORDER#42") == {"pk": {"S": "ORDER#42"}} stub.assert_no_pending_responses()

The credentials are dummy test values and the stub prevents a network request. Add separate cases for missing items, pagination, conditional failures and retryable errors where your code handles them. Reset mocks between tests so call history and responses do not leak.

The same boundary applies to JavaScript v3 command clients and Java or .NET interfaces. Use DynamoDB Local for request and expression integration tests, then validate IAM, throttling and service-specific behavior against AWS. Local behavior is not identical to production.

See boto3 examples for the underlying calls.

Source: botocore Stubber.

Dynobase is a Professional GUI Client for DynamoDB

Start your 7-day free trial today

Product Features

Download
/
Changelog
/
Pricing
/
Member Portal
/
Privacy
/
EULA
/
Twitter
© 2026 Dynobase
+
Still using AWS DynamoDB Console?
Try Dynobase to accelerate your DynamoDB workflow. Start your 7-day free trial today.