I'm implementing a flow for recreating a DynamoDB table with the following steps:
- check if the table exists, if not go to step 4
- run the delete table command
- wait until table is deleted
- run the create table command
- wait until table is created
Here is simple code of given flow
const recreateTable = async (tableName, tableDefinition) => {
// step 1
const command = new ListTablesCommand({});
const { TableNames } = await dynamoDb.send(command);
const tableExists = TableNames.includes(tableName);
if (tableExists) {
// step 2
const command = new DeleteTableCommand({ TableName: tableName });
await dynamoDb.send(command);
// step 3
await waitUntilTableNotExists({ client: dynamoDb, minDelay: 5, maxDelay: 30, maxWaitTime: 120 }, { TableName: tableName });
}
// step 4
const definition = {
...tableDefinition,
TableName: tableName,
};
await dynamoDb.send(new CreateTableCommand(definition));
// step 5
await waitUntilTableExists({ client: dynamoDb, maxWaitTime: 120 }, { TableName: tableName });
};
The problem is that during step 3, execution doesn't go any further, waiter reaches timeout and throws an error. Increasing timeout duration or changing/adding/removing other params in the waiter doesn't help.
This reproduces both on local hosting and on instance
Here are some additional conclusions:
- Table deletion lasts for maybe 10-20 seconds, so there is no obvious reason for waiter method to hold for 2,5,10 minutes and still throw a timeout error
- If I call
recreateTableonce again, the flow will skip steps 2,3 and immediately starts runningCreateTableCommandandwaitUntilTableExists, which works as expected
I totally understand that this can be solved by simply adding try-catch wrappers and using acustom waiter method with basic polling instead of waitUntilTableNotExists but I'm still keen to understand why this is happening