From 3e498201e59edf28156bdccf569e0a7bb3f71da4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristian=20Pallar=C3=A9s?= Date: Wed, 3 Apr 2024 09:40:31 +0200 Subject: [PATCH] fix(dynamodb): ensure table is ready Use the DescribeTable operation on a table to ensure that the table is ready. --- dynamodb/dynamodb.extern.d.ts | 1 + dynamodb/dynamodb.sim.w | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/dynamodb/dynamodb.extern.d.ts b/dynamodb/dynamodb.extern.d.ts index 13beeb26..2aafda7c 100644 --- a/dynamodb/dynamodb.extern.d.ts +++ b/dynamodb/dynamodb.extern.d.ts @@ -17,6 +17,7 @@ export interface ClientConfig { export interface Client$Inflight { readonly createTable: (input: Readonly) => Promise>; readonly deleteTable: (input: Readonly) => Promise>; + readonly describeTable: (input: Readonly) => Promise>; readonly updateTimeToLive: (input: Readonly) => Promise>; } export interface Credentials { diff --git a/dynamodb/dynamodb.sim.w b/dynamodb/dynamodb.sim.w index 745623f6..aeb8a5e9 100644 --- a/dynamodb/dynamodb.sim.w +++ b/dynamodb/dynamodb.sim.w @@ -8,6 +8,7 @@ interface Client { inflight createTable(input: Json): Json; inflight deleteTable(input: Json): Json; inflight updateTimeToLive(input: Json): Json; + inflight describeTable(input: Json): Json; } class Util { @@ -140,7 +141,7 @@ pub class Table_sim impl dynamodb_types.ITable { })(); // delete the table if it already exists because we might be reusing the container - try { client.deleteTable({ TableName: tableName }); } + try { client.deleteTable({ TableName: tableName }); } catch e { } util.waitUntil(() => { @@ -167,6 +168,15 @@ pub class Table_sim impl dynamodb_types.ITable { }); } + // Wait until we can describe the table. This is + // to ensure that the table is ready to be used. + util.waitUntil(() => { + client.describeTable({ + TableName: tableName, + }); + return true; + }); + state.set("tableName", tableName); return true; } catch error {