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')
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.
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.
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.
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.
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.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With