Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wait for complete deletion of a DynamoDB table using boto3

I need to delete a dynamodb table, and wait until it is completely removed. How can I check this?
boto3 api expose a method get_waiter to wait for certain events, but it is not well documented. Can I use it for this purpose? Which would be the event name, or maybe handle a ResourceNotFoundException

# Wait until the table exists.
table.meta.client.get_waiter('table_exists').wait(TableName='TableName')
like image 315
Yasel Avatar asked Jul 19 '16 21:07

Yasel


People also ask

How long does it take to delete table DynamoDB?

When you delete a table, any indexes on that table are also deleted. If you have DynamoDB Streams enabled on the table, then the corresponding stream on that table goes into the DISABLED state, and the stream is automatically deleted after 24 hours. Use the DescribeTable action to check the status of the table.

How do I delete data from DynamoDB table?

With the DynamoDB API, you use the DeleteItem action to delete data from a table, one item at a time. You must specify the item's primary key values. In addition to DeleteItem , Amazon DynamoDB supports a BatchWriteItem action for deleting multiple items at the same time.

How do I delete multiple rows in DynamoDB?

To delete a single item, use DeleteItem. To delete multiple items, use BatchWriteItem. Despite the naming of BatchWriteItem , it can be used to put multiple items or to delete multiple items, and you can target one or more DynamoDB tables in the same API call.

How do I delete a table in DynamoDB local?

The DeleteTable operation deletes a table and all of its items. After a DeleteTable request, the specified table is in the DELETING state until DynamoDB completes the deletion. If the table is in the ACTIVE state, you can delete it.


2 Answers

After delete_table API, call table_not_exists waiter. This waits until the specified table returns 404.

import boto3
client = boto3.client('dynamodb')
client.delete_table(TableName='foo')
waiter = client.get_waiter('table_not_exists')
waiter.wait(TableName='foo')
print ("table deleted")

For create_table API, call table_exists waiter. This waits until the specified table gets active.

like image 91
quiver Avatar answered Oct 14 '22 10:10

quiver


Without waiter,Now we can use wait_until_not_exists function like below example

table = dynamoResources.Table(table_name)
table.delete()
table.wait_until_not_exists()
like image 23
Alimon Karim Avatar answered Oct 14 '22 09:10

Alimon Karim