DynamoDB ResourceInUseException
TL;DR — You tried a table operation on a table that already exists or is still transitioning (CREATING / UPDATING / DELETING). Check the table's status first, or make the create idempotent by ignoring "already exists".
What it means
ResourceInUseException: Table already exists: <name>
ResourceInUseException: Attempt to change a resource which is still in use: Table is being created/deletedControl-plane operations (CreateTable, DeleteTable, UpdateTable) require the table to be in a compatible state. This error means it isn't — either it already exists, or it's mid-transition and DynamoDB won't accept another operation until it settles to ACTIVE.
Why it happens
- Re-running
CreateTablefor a table that already exists (a repeated migration/deploy, tests that don't clean up). - Operating during a transition — creating an index, deleting, or updating while the table is still
CREATING/UPDATING. - A race — two processes creating the same table concurrently.
How to fix it
- Check status before acting.
DescribeTable→ only proceed whenTableStatusisACTIVE; use a waiter (waitUntilTableExists) to block until it settles. - Make create idempotent. Catch
ResourceInUseExceptiononCreateTableand treat it as success (the table you wanted exists). - Serialize table ops in tests/migrations so two don't run at once; clean up test tables in teardown.
Example
import {DynamoDBClient, CreateTableCommand, ResourceInUseException} from '@aws-sdk/client-dynamodb';
const client = new DynamoDBClient({});
try {
await client.send(new CreateTableCommand(tableDef));
} catch (err) {
if (!(err instanceof ResourceInUseException)) throw err;
// Table already exists — that's fine, carry on.
}Related errors
- ResourceNotFoundException — the table doesn't exist.
- ThrottlingException — too many control-plane ops.