> ## Documentation Index
> Fetch the complete documentation index at: https://phidatainc.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

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

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U agno boto3 openai
    ```
  </Step>

  <Step title="Export environment variables">
    <CodeGroup>
      ```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"
      ```
    </CodeGroup>
  </Step>

  <Step title="Run the example">
    Save the code above as `dynamo_for_agent.py`, then run:

    ```bash theme={null}
    python dynamo_for_agent.py
    ```
  </Step>
</Steps>

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