LangGraph AWS Checkpoint
The `langgraph-checkpoint-aws` library provides a LangGraph checkpointer implementation that leverages AWS Bedrock Session Management Service (SMS) for session storage and AWS ElastiCache Valkey (Redis) for state management. It enables stateful and resumable LangGraph agents, allowing them to persist and retrieve their execution state across invocations. The current version is 1.0.7, and its release cadence is tied to the LangChain ecosystem, implying active development and frequent updates.
Common errors
-
redis.exceptions.ConnectionError: Error 111 connecting to localhost:6379. Connection refused.
cause The Redis/Valkey server is not running or is not accessible at the specified host and port.fixStart your Redis/Valkey server. Verify the `REDIS_URL` environment variable or the host/port in your `redis.from_url()` call is correct and that no firewall is blocking the connection. -
botocore.exceptions.ClientError: An error occurred (AccessDeniedException) when calling the PutItem operation: User: arn:aws:iam::123456789012:user/myuser is not authorized to perform: dynamodb:PutItem on resource: arn:aws:dynamodb:us-east-1:123456789012:table/BedrockSessionManager
cause The AWS credentials used by your application lack the necessary IAM permissions to interact with the DynamoDB table used by Bedrock Session Management Service (or a custom table you specified).fixGrant the IAM user or role associated with your application `dynamodb:PutItem`, `dynamodb:GetItem`, and `dynamodb:UpdateItem` permissions on the target DynamoDB table. Ensure `AWS_REGION` is also correctly configured. -
ValueError: Must specify a 'thread_id' in the config under ['configurable'] when using a checkpointer.
cause When a checkpointer is enabled, LangGraph requires a `thread_id` to be provided in the `config` object during `invoke()` or `stream()` calls to manage the state of a specific conversational thread.fixEnsure your `config` dictionary passed to `graph.invoke()` includes `{'configurable': {'thread_id': 'your_unique_thread_id'}}`.
Warnings
- gotcha Ensure AWS credentials and necessary IAM permissions are configured for your environment. The checkpointer interacts with AWS DynamoDB (via Bedrock Session Management Service) and potentially other AWS services. Missing permissions (e.g., `dynamodb:PutItem`, `dynamodb:GetItem`, `dynamodb:UpdateItem`) will lead to `AccessDeniedException` errors.
- gotcha The checkpointer requires a running and accessible Redis or Valkey instance. Connection errors (`redis.exceptions.ConnectionError`) are common if the host, port, or password are incorrect, or if the instance is not running or is behind a firewall.
- gotcha The `application_id` parameter for `AWSSessionManagerValkeySaver` is crucial for partitioning state within Bedrock Session Management Service (DynamoDB). Using different `application_id` values will result in separate state storage for the same `thread_id`.
Install
-
pip install langgraph-checkpoint-aws
Imports
- AWSSessionManagerValkeySaver
from langgraph_checkpoint_aws import AWSSessionManagerValkeySaver
Quickstart
import os
import redis
import boto3
from langgraph.graph import StateGraph, START
from langgraph.checkpoint.base import Checkpoint
from langgraph_checkpoint_aws import AWSSessionManagerValkeySaver
# 1. Setup AWS client (ensure AWS credentials are configured, e.g., via ~/.aws/credentials or env vars)
# The Checkpointer primarily uses DynamoDB via Bedrock Session Management Service.
aws_region = os.environ.get("AWS_REGION", "us-east-1")
boto3_session = boto3.Session(region_name=aws_region)
# 2. Setup Valkey/Redis client
# Ensure a Redis/Valkey instance is running and accessible (e.g., local or ElastiCache)
redis_url = os.environ.get("REDIS_URL", "redis://localhost:6379/0")
try:
redis_client = redis.from_url(redis_url)
redis_client.ping() # Test connection
except redis.exceptions.ConnectionError:
print(f"WARNING: Could not connect to Redis at {redis_url}. Please ensure a Redis/Valkey instance is running.")
redis_client = None # Mark as failed
# 3. Define a simple LangGraph state
class AgentState(dict):
"""A dictionary-like state for the graph."""
pass
# 4. Instantiate the AWSSessionManagerValkeySaver
# 'application_id' is used to partition state within Bedrock SMS/DynamoDB.
application_id = os.environ.get("AWS_APPLICATION_ID", "my_langgraph_app_dev")
if redis_client:
checkpointer = AWSSessionManagerValkeySaver(
boto3_session=boto3_session,
redis_client=redis_client,
application_id=application_id
# Optional: You can specify a custom DynamoDB table name if not using the default Bedrock SMS table.
# table_name="MyCustomLangGraphCheckpoints"
)
# 5. Build a simple LangGraph with the checkpointer
graph_builder = StateGraph(AgentState)
graph_builder.add_node("start_node", lambda state: {"message": "Hello from LangGraph!"})
graph_builder.set_entry_point("start_node")
graph_builder.set_finish_point("start_node")
# Compile the graph with the checkpointer
app = graph_builder.compile(checkpointer=checkpointer)
# 6. Run the graph with a configurable thread_id for checkpointing
thread_id = "unique_session_123"
config = {"configurable": {"thread_id": thread_id}}
print(f"Running LangGraph with checkpointer for thread_id: {thread_id}")
# The first run will create a checkpoint
result = app.invoke({}, config=config)
print(f"First run output: {result}")
# Subsequent runs with the same thread_id will load the checkpoint
# (in a more complex graph, state would be loaded and updated)
result_again = app.invoke({}, config=config)
print(f"Second run output (should be same for this simple graph): {result_again}")
print("\nSuccessfully configured AWSSessionManagerValkeySaver and ran a simple graph.")
print("Check your AWS Bedrock Session Manager (DynamoDB) and Valkey/Redis instance for stored state.")
else:
print("Checkpointer instantiation skipped due to Redis connection failure.")
print("Please ensure REDIS_URL and AWS credentials are correctly configured.")