
Trying Out DynamoDB Caching with Amazon ElastiCache Serverless for Valkey
This page has been translated by machine translation. View original
Introduction
On 2026-11-17, DynamoDB caching for Amazon ElastiCache Serverless for Valkey was announced.
DynamoDB caching is a feature that routes reads from DynamoDB through an ElastiCache Serverless for Valkey cache. This article presents the results of trying DynamoDB caching with the Python integration client.
Creating and Connecting to the Cache
The test environment was the Tokyo region (ap-northeast-1) with Valkey 9.0. On the client side, I used aws-elasticache-integration-client 1.0.0, boto3 1.44.5, and Python 3.12, and the AWS CLI was 2.41.0.
Creating the Cache
Specify the DynamoDB integration with --integrations at creation time.
aws elasticache create-serverless-cache \
--serverless-cache-name devio-ddb-cache-a \
--engine valkey --major-engine-version 9 \
--integrations IntegrationType=DYNAMODB \
--user-group-id default.iam-user-group \
--connection-type public
DynamoDB caching can be used with engine version Valkey 9 or later. Authentication is IAM only, so I specified default.iam-user-group, the user group for IAM authentication.
After creation, get the endpoint with describe-serverless-caches.
aws elasticache describe-serverless-caches --serverless-cache-name devio-ddb-cache-a
{
"ServerlessCaches": [
{
"ServerlessCacheName": "devio-ddb-cache-a",
"Status": "available",
"Engine": "valkey",
"MajorEngineVersion": "9",
"FullEngineVersion": "9.0",
"Endpoint": {
"Address": "devio-ddb-cache-a-<id>.public.serverless.apne1.cache.amazonaws.com",
"Port": 6379
},
"UserGroupId": "default.iam-user-group",
"ConnectionType": "public",
"Integrations": [
{
"IntegrationType": "dynamodb",
"Status": "enabled"
}
]
}
]
}
From the start of creation at 15:44:20 to 15:45:32, when available was confirmed by polling at 15-second intervals, it took about 72 seconds. The Integrations Status was already enabled in the response to the create command.
Because I connected from a local PC outside the VPC, I chose public as the connection type. From a Docker container on the PC, I connected using the Endpoint Address and port 6379 and confirmed that reads worked.
Client Configuration
For IAM permissions, elasticache:Connect is required in addition to the usual DynamoDB permissions. The Python version's README lists both the cache and the ElastiCache user (default is default.iam-user) as targets of Connect. Because I ran the verification with a role that has AdministratorAccess, I did not confirm the range of permissions actually required. Please refer to the user guide.
We use the Python aws-elasticache-integration-client.
pip install aws-elasticache-integration-client==1.0.0
On the application side, add install to the boto3 DynamoDB client. From then on, get_item and put_item on this client go through the cache.
import boto3
import aws_elasticache_integration_client
ddb = boto3.client("dynamodb", region_name="ap-northeast-1")
aws_elasticache_integration_client.install(
client=ddb,
endpoint="<endpoint-address>:6379",
cache_name="devio-ddb-cache-a",
)
Verifying the Behavior
I use a client that does not go through the cache and a client with install applied, and check which value can be read after an update. The test table is an on-demand table with a partition key id (string type).
aws dynamodb create-table --table-name devio-ddbcache-verify \
--attribute-definitions AttributeName=id,AttributeType=S \
--key-schema AttributeName=id,KeyType=HASH \
--billing-mode PAY_PER_REQUEST
Save the function that creates the two clients and the read/write helper functions as check_cache.py, then load it with python -i check_cache.py and operate interactively. For ENDPOINT, enter the Address and port obtained with describe-serverless-caches.
from typing import Any
import boto3
import aws_elasticache_integration_client as ec
from aws_elasticache_integration_client import ElastiCacheIntegrationsClientConfiguration
REGION = "ap-northeast-1"
TABLE = "devio-ddbcache-verify"
ENDPOINT = "<endpoint-address>:6379"
CACHE_NAME = "devio-ddb-cache-a"
def make_direct() -> Any:
return boto3.client("dynamodb", region_name=REGION)
def make_cached(overrides: dict[str, Any] | None = None) -> Any:
ddb = boto3.client("dynamodb", region_name=REGION)
ec.install(
client=ddb,
endpoint=ENDPOINT,
cache_name=CACHE_NAME,
client_configuration=ElastiCacheIntegrationsClientConfiguration(
cache_policy_overrides=overrides
),
)
return ddb
def put_value(client: Any, key: str, value: str) -> None:
client.put_item(TableName=TABLE, Item={"id": {"S": key}, "value": {"S": value}})
def get_value(client: Any, key: str, **kwargs: Any) -> tuple[str | None, float | None]:
resp = client.get_item(TableName=TABLE, Key={"id": {"S": key}}, **kwargs)
value = resp.get("Item", {}).get("value", {}).get("S")
consumed = resp.get("ConsumedCapacity", {}).get("CapacityUnits")
return value, consumed
Hereafter, a put_item (including creating an item) with the client created by make_direct is called a "direct update".
How to Tell Whether It Was a Hit
You can tell whether an individual get_item was a hit by specifying ReturnConsumedCapacity=TOTAL. The consumed read capacity is included in the response as CapacityUnits. An item not in the cache is read from DynamoDB, so it is 0.5, and an item in the cache is 0.0. In the following code, I read a directly created item three times under the same conditions.
direct = make_direct()
cached = make_cached()
put_value(direct, "hit-1", "v1")
get_value(cached, "hit-1", ReturnConsumedCapacity="TOTAL")
get_value(cached, "hit-1", ReturnConsumedCapacity="TOTAL")
get_value(cached, "hit-1", ReturnConsumedCapacity="TOTAL")
CapacityUnits was 0.5, 0.0, 0.0. Only the first was a read from DynamoDB (a miss), and the second and later were hits.
For hits on normal reads without ReturnConsumedCapacity, check the CloudWatch metrics. After one miss, I read the same key 100 times.
cached = make_cached()
put_value(make_direct(), "metrics-1", "m1")
for _ in range(101):
get_value(cached, "metrics-1")
The namespace is AWS/ElastiCache. The user guide lists the dimensions as ClusterId, TableName, and Operation. However, the dimension names returned by list-metrics were clusterId, table, and operation. In the CLI, specify the names returned by list-metrics.
START=2026-11-18T06:50:00Z; END=2026-11-18T06:56:00Z
for m in DynamoDBCachingHits:Sum DynamoDBCachingMisses:Sum DynamoDBCachingHitRate:Average; do
echo "## ${m%%:*} (${m##*:}, period 60s)"
aws cloudwatch get-metric-statistics --namespace AWS/ElastiCache --metric-name ${m%%:*} \
--dimensions Name=clusterId,Value=devio-ddb-cache-a Name=operation,Value=GetItem Name=table,Value=devio-ddbcache-verify \
--start-time $START --end-time $END --period 60 --statistics ${m##*:} \
--query "sort_by(Datapoints,&Timestamp)[].[Timestamp,${m##*:}]" --output text
done
## DynamoDBCachingHits (Sum, period 60s)
2026-11-18T15:51:00+09:00 100.0
## DynamoDBCachingMisses (Sum, period 60s)
2026-11-18T15:51:00+09:00 1.0
## DynamoDBCachingHitRate (Average, period 60s)
2026-11-18T15:51:00+09:00 0.9900990099009901
In this measurement, there was no data point about 3 minutes after the reads, and it became available about 5 minutes after.
Reads After a Direct Update
I directly updated a cached item (v1) to v2 and ran get_item through the cache four times in the order shown in the table below.
| Operation (get_item through the cache) | Returned value |
|---|---|
| Normal read (immediately after the direct update) | v1 |
| Read with ReturnConsumedCapacity=TOTAL specified | v2 (consumed 0.5) |
| Read with ConsistentRead set to true | v2 |
| Normal read (afterward) | v2 |
Even after the direct update, a normal get_item returned the old value (v1). With ConsistentRead set to true, the latest value (v2) was returned, and after that, normal reads also returned v2. Reads after the TTL expires also return the latest value (I try this in the TTL section).
In a setup where another application updates DynamoDB directly, set ConsistentRead to true for reads that need freshness.
Writes Through the Cache
I ran put_item and delete_item through the cache on an item that had already been read and on an item that had not yet been read.
| Operation (through the cache) | Read through the cache immediately afterward |
|---|---|
| put_item on an already-read item (v1 to v2) | v2 |
| delete_item on an already-read item | No item (None) |
| put_item (w1) on a not-yet-read item, then update to w2 without going through the cache | w2 |
An item that has not yet been read does not enter the cache even if it is written through the cache.
Retention Time and Target Specification
The cache retention time and targets can be specified in the settings passed to install.
The setting names for TTL are ttl and negative_ttl in the user guide. In the Python version, they are item_ttl and item_negative_ttl in cache_policy_overrides.
TTL
The default TTL is 5 minutes. I set item_ttl to 5 seconds and checked whether it can be changed.
cached = make_cached({"item_ttl": 5})
After reading v1 through the cache and then directly updating it to v2, the read immediately afterward was v1. The read after waiting 6 seconds was v2.
Negative Cache
The result of reading a nonexistent item (None) remains as a negative cache. The default TTL of the negative cache is 60 seconds.
After reading a nonexistent item and getting None, I created that item with a direct put_item. A normal read through the cache remained None. With ConsistentRead set to true, the value was returned, and after that, normal reads also returned the value.
When I tried the same steps with a client with item_negative_ttl set to 0, the normal read immediately after creation returned the value.
cached = make_cached({"item_negative_ttl": 0})
Narrowing Down Target Tables and Operations
With cached_tables you can narrow the tables to be cached, and with cached_operations you can narrow the target operations. According to the user guide, the following 10 APIs support caching.
- Item-level: GetItem, PutItem, UpdateItem, DeleteItem
- Batch: BatchGetItem, BatchWriteItem
- Search: Query, Scan
- Transactions: TransactGetItems, TransactWriteItems
I compared how direct updates appear with the following two settings.
make_cached({"cached_tables": ["some-other-table"]})
make_cached({"cached_tables": [TABLE], "cached_operations": ["GetItem"]})
| Setting | Read after a direct update |
|---|---|
| cached_tables set to a different table name | Latest value |
| cached_tables set to the test table, cached_operations set to GetItem | Old value |
In the first case, the test table is outside the cache targets, so the direct update was reflected. In the second case, both the table read and the operation (GetItem) are included in the specification, so the cache took effect and the old value was returned.
Summary
The newly supported DynamoDB caching, unlike DAX, requires no node management, and it can be used with pay-as-you-go pricing based on Amazon ElastiCache Serverless for Valkey requests and consumed storage.
On the application side, simply adding install to an SDK that supports DynamoDB caching (the boto3 client) let me use the cache without changing the get_item or put_item code. The languages supported at release are three: Python, Node.js, and Java.
For workloads with many reads to DynamoDB where caching is effective, and where you want to avoid custom cache control implementations and node management, please consider it as an option.
References
