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

# Use DynamoDB as the database for an agent

> Store agent sessions and runs in DynamoDB using AWS credentials from the environment.

```python dynamo_for_agent.py 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

<Snippet file="create-venv-step.mdx" />

**1. Install dependencies**

```bash theme={null}
uv pip install -U agno boto3 openai
```

**2. Export environment variables**

```bash Mac/Linux theme={null}
export AWS_ACCESS_KEY_ID="your_aws_access_key_id_here"
export AWS_REGION="your_aws_region_here"
export AWS_SECRET_ACCESS_KEY="your_aws_secret_access_key_here"
export OPENAI_API_KEY="your_openai_api_key_here"
```

```bash Windows theme={null}
$Env:AWS_ACCESS_KEY_ID="your_aws_access_key_id_here"
$Env:AWS_REGION="your_aws_region_here"
$Env:AWS_SECRET_ACCESS_KEY="your_aws_secret_access_key_here"
$Env:OPENAI_API_KEY="your_openai_api_key_here"
```

**3. Run the example**

Save the code above as `dynamo_for_agent.py`, then run:

```bash theme={null}
python dynamo_for_agent.py
```

Full source: [cookbook/06\_storage/dynamodb/dynamo\_for\_agent.py](https://github.com/agno-agi/agno/blob/v3.0.4/cookbook/06_storage/dynamodb/dynamo_for_agent.py)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.