Reputation: 5778
How to wait for dynamodb instance table to be created before starting inserting elements?
dynamodb = boto3.client('dynamodb', region_name="eu-west-3")
dynamodb.create_table(
TableName='mytable',
KeySchema=[
{
'AttributeName': 'id',
'KeyType': 'HASH' # Partition key
}
# no sort key
],
AttributeDefinitions=[
{
'AttributeName': 'id',
'AttributeType': 'S'
},
],
BillingMode='PAY_PER_REQUEST',
)
When I start my batch, I receive because the table is not created yet:
botocore.errorfactory.ResourceNotFoundException:
An error occurred (ResourceNotFoundException) when calling the BatchWriteItem operation:
Requested resource not found
I would like to wait for the end of the creation of the table. How to do it?
Upvotes: 3
Views: 1920
Reputation: 5778
You can use this to wait for the end of the creation of the table:
waiter = dynamodb.get_waiter('table_exists')
waiter.wait(TableName='mytable')
# at this line your table is fully created and available
as described in the documentation: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/clients.html#waiters
Upvotes: 5