python - 等待dynamodb创建表,避免Requested resource not found
问题描述
如何在开始插入元素之前等待创建 dynamodb 实例表?
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',
)
当我开始我的批处理时,我收到因为表尚未创建:
botocore.errorfactory.ResourceNotFoundException:
An error occurred (ResourceNotFoundException) when calling the BatchWriteItem operation:
Requested resource not found
我想等待表的创建结束。怎么做?
解决方案
您可以使用它来等待表的创建结束:
waiter = dynamodb.get_waiter('table_exists')
waiter.wait(TableName='mytable')
# at this line your table is fully created and available
如文档中所述:https ://boto3.amazonaws.com/v1/documentation/api/latest/guide/clients.html#waiters
推荐阅读
- mysql - MYSQL查询优化题使用Count和2个表
- javascript - 检测 Chrome 和 Edge Chromium 在我的网站上不起作用
- reactjs - 反应 event.target 设置状态。设置列表项背景颜色
- excel - 问:如何以横向格式打印 EXCEL / VBA 用户表单?
- spring-boot - 这些 Google 登录方法有什么区别?
- react-native - 使用 axios 在本机反应中发送文件时出现网络错误
- ruby-on-rails-5 - ROR - 尝试使用嵌套表单创建对象
- python - 谷歌云虚拟机实例的硒替代品?
- c++ - 为什么我在 devc++ 中编译代码时会出现此错误?
- angular - 在数据库错误消息中找不到电子邮件