等待在 dynamodb 中创建 table 以避免找不到请求的资源
Wait for the table to be created in dynamodb to avoid Requested resource not found
如何在开始插入元素之前等待 dynamodb 实例 table 创建?
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',
)
当我开始我的批处理时,我收到了,因为 table 还没有创建:
botocore.errorfactory.ResourceNotFoundException:
An error occurred (ResourceNotFoundException) when calling the BatchWriteItem operation:
Requested resource not found
我想等待创作结束table。怎么做?
你可以用这个来等待创建结束 table:
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
如何在开始插入元素之前等待 dynamodb 实例 table 创建?
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',
)
当我开始我的批处理时,我收到了,因为 table 还没有创建:
botocore.errorfactory.ResourceNotFoundException:
An error occurred (ResourceNotFoundException) when calling the BatchWriteItem operation:
Requested resource not found
我想等待创作结束table。怎么做?
你可以用这个来等待创建结束 table:
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