> For the complete documentation index, see [llms.txt](https://docs.p0.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.p0.dev/agentic-access/agentic-gateway/mcp-server/dynamodb.md).

# Amazon DynamoDB MCP server

Install the DynamoDB (AI) integration and the Amazon DynamoDB MCP server so agents behind the P0 AI Gateway can request temporary read or write access to one DynamoDB table.

The **DynamoDB (AI)** integration lets agents behind the [P0 Runtime Access for AI](https://docs.p0.dev/readme/agentic-control-plane.md) request temporary access to one DynamoDB table and its indexes, in one AWS account and Region. For each approved request, P0 adds an IAM policy statement for that table to a role from your [AWS OIDC](https://docs.p0.dev/agentic-access/credential-sources/aws-oidc.md) role pool. The statement works only for the agent's session, and only until the grant ends. The gateway assumes the role and runs P0's **Amazon DynamoDB** MCP server with its credentials, so IAM decides what each call can do.

Only agents can use this integration. People request DynamoDB access through the [AWS](https://docs.p0.dev/integrations/resource-integrations/aws.md) integration.

{% hint style="info" %}
The DynamoDB (AI) integration is in beta. Functionality and configuration may change.
{% endhint %}

## Prerequisites

* A registered [Gateway](https://docs.p0.dev/agentic-access/agentic-gateway/gateway.md) component, with the gateway deployed in your environment.
* P0's AWS **IAM management** installed for the AWS account. See [Setting up AWS IAM management](https://docs.p0.dev/integrations/resource-integrations/aws/installation-methods.md).
* The [AWS OIDC](https://docs.p0.dev/agentic-access/credential-sources/aws-oidc.md) component installed for the same account.
* To let agents list tables, [AWS Resource Explorer](https://docs.aws.amazon.com/resource-explorer/latest/userguide/getting-started-setting-up.html) turned on in the account, with an index in each Region that has tables. Without an index, agents can still request a table by name.

The install adds nothing in AWS. P0 uses the IAM management role to find tables, and the AWS OIDC role pool to grant access.

## Install an AWS account

1. Navigate to **Integrations** on [p0.app](https://p0.app), select **DynamoDB (AI)**, and choose the **IAM management** component.
2. Add an account. P0 lists only AWS accounts where its AWS IAM management is installed. Click **Next**.
3. P0 checks that AWS OIDC federation is installed for the account, and that it can search the account with Resource Explorer. Review the summary and click **Finish**. The account now appears with the state **Installed**.

### Install with Terraform

{% hint style="info" %}
The `p0_dynamodb_ai` resource requires [P0 Terraform provider v0.86.0](https://github.com/p0-security/terraform-provider-p0/releases/tag/v0.86.0) or later.
{% endhint %}

Instead of the installer, you can install each account with the P0 Terraform provider (see [Manage integrations as code with the P0 Terraform provider](https://docs.p0.dev/getting-started/get-started-with-the-p0-terraform-provider.md)). Create [`p0_dynamodb_ai`](https://registry.terraform.io/providers/p0-security/p0/latest/docs/resources/dynamodb_ai) with `id` set to the AWS account ID, after the account's `p0_aws_iam_write` and `p0_aws_oidc_identity` resources:

```hcl
resource "p0_dynamodb_ai" "example" {
  id = "123456789012"
  depends_on = [
    p0_aws_iam_write.example,
    p0_aws_oidc_identity.example,
  ]
}
```

## Add the Amazon DynamoDB MCP server

You can add the server once at least one account is installed.

1. Follow the shared steps in [MCP server](https://docs.p0.dev/agentic-access/agentic-gateway/mcp-server.md#add-an-mcp-server) to name the server and choose its gateway. On the configuration screen, set the following fields, then click **Finish**:
   * **Credential source**: choose **AWS IAM federation**, then select the **Federation provider**: the [AWS OIDC](https://docs.p0.dev/agentic-access/credential-sources/aws-oidc.md) identity for the account that holds your tables.
   * **Definition**: choose **P0**, then select **Amazon DynamoDB**.
2. The server now appears with the state **Installed**.

A federation provider maps to one AWS account. To reach tables in another account, add a second server with that account's AWS OIDC identity.

## How agents request access

An agent requests access with the server's `access` tool. It names an installed AWS account by its ID, the table's Region, the table's name, and a level. The equivalent CLI request is:

```bash
p0 request dynamodb-ai table <account> <region> <table> <level> --reason "<reason>"
```

The grant covers the table and all of its indexes. The level is `read` or `write`:

| Level   | Tools                                                                              | IAM actions granted                                                                                                                                               |
| ------- | ---------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `read`  | `describe_table`, `get_item`, `batch_get_item`, `query`, `scan`                    | `dynamodb:GetItem`, `BatchGetItem`, `Query`, `Scan`, `PartiQLSelect`, `DescribeTable`, `DescribeTimeToLive`                                                       |
| `write` | The `read` tools, and `put_item`, `update_item`, `delete_item`, `batch_write_item` | The `read` actions, and `dynamodb:PutItem`, `UpdateItem`, `DeleteItem`, `BatchWriteItem`, `ConditionCheckItem`, `PartiQLInsert`, `PartiQLUpdate`, `PartiQLDelete` |

`scan` reads every item in the table, so `read` lets an agent read the whole table. `write` lets it change or delete any item in the table.

Items go in and out of the tools as plain JSON, such as `{"pk": "user#1", "count": 3}`. Each call returns at most 1 MB.

Once a request is approved, access usually works within about 10 seconds, and can take up to 30 seconds. When the grant ends, calls stop working within the same time.

P0 refuses a request in these cases, with a message that says why:

* It didn't come from an agentic session.
* The account isn't installed in DynamoDB (AI).
* The Region or table name isn't one AWS allows.

If every role in the account's AWS OIDC role pool is full, an approved request fails. Revoke unused access, or add roles to the pool, then request again.

P0 doesn't check that the table exists. A grant on a table that doesn't exist gives no access.

{% hint style="warning" %}
A table encrypted with a customer managed AWS KMS key can't be read or written through this server, because the grant includes no KMS permissions. Tables encrypted with an AWS owned or AWS managed key work.
{% endhint %}

See [Requesting access](https://docs.p0.dev/agentic-access/using-the-gateway/requesting-access.md) for how agents submit and use requests.

## Write policies for DynamoDB

Match DynamoDB requests in an agentic access policy (see [Agentic access policies](https://docs.p0.dev/agentic-access/agentic-access-policies.md)) with `service: dynamodb-ai` and `accessType: table`. These filters narrow them:

| Filter    | Key    | What it matches    | Example        |
| --------- | ------ | ------------------ | -------------- |
| `account` | `id`   | The AWS account ID | `123456789012` |
| `region`  | `name` | The table's Region | `us-west-2`    |
| `table`   | `name` | The table's name   | `orders-prod`  |
| `level`   | `name` | `read` or `write`  | `read`         |

Policies are the only limit on what agents can request. Every table in an installed account can be requested, so write a policy for each kind of access you allow. Agents see only the tables their policies let them request.

Patterns are case-sensitive regular expressions, and they match anywhere in a value. Start each pattern with `^` and end it with `$`. A pattern without anchors matches more than it looks like it does: `orders` also matches `old-orders-archive`.

This policy auto-approves `read` access to every table whose name starts with `orders-`, in one account, for one agent:

```yaml
- requestor:
    type: agentic
    actor:
      type: agent-client
      clientId: reporting-agent
    subject:
      type: any
  resource:
    type: integration
    service: dynamodb-ai
    accessType: table
    filters:
      account:
        effect: keep
        key: id
        pattern: ^123456789012$
      table:
        effect: keep
        key: name
        pattern: ^orders-
      level:
        effect: keep
        key: name
        pattern: ^read$
  approval:
    - type: persistent
```

## Remove the integration

1. **Remove the Amazon DynamoDB MCP server** from your gateway.
2. **End or revoke every active grant**, so that P0 removes each grant's statement from the role pool.
3. **Delete each account** from the **DynamoDB (AI)** integration in P0.

## Next steps

* Define the [Agentic access policies](https://docs.p0.dev/agentic-access/agentic-access-policies.md) that decide which agents and users can request DynamoDB access.
