> ## Documentation Index
> Fetch the complete documentation index at: https://phidatainc-studio-tools-doc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Use DynamoDb as the database for an agent.

> Use DynamoDB as the storage backend for an agent.

Set the following environment variables to connect to your DynamoDb instance: - AWS\_ACCESS\_KEY\_ID - AWS\_SECRET\_ACCESS\_KEY - AWS\_REGION

```python theme={null}
"""Use DynamoDb as the database for an agent.

Set the following environment variables to connect to your DynamoDb instance:
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
- AWS_REGION

Run `uv pip install boto3` to install dependencies."""

from agno.agent import Agent
from agno.db import DynamoDb

# ---------------------------------------------------------------------------
# Setup
# ---------------------------------------------------------------------------
db = DynamoDb()

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(
    db=db,
    name="DynamoDB Agent",
    description="An agent that uses DynamoDB as a database",
    add_history_to_context=True,
)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    # The Agent sessions and runs will now be stored in DynamoDB
    agent.print_response("How many people live in Canada?")
    agent.print_response("What is their national anthem called?")
```

## Run the Example

```bash theme={null}
# Clone and setup repo
git clone https://github.com/agno-agi/agno.git
cd agno/cookbook/06_storage/dynamodb

# Create and activate virtual environment
./scripts/demo_setup.sh
source .venvs/demo/bin/activate

python dynamo_for_agent.py
```
