Boto3 和 AWS RDS:正确等待从快照创建数据库
Boto3 and AWS RDS: properly wait for database creation from snapshot
我的 Lambda(Python 和 Boto3)中有以下代码:
rds.restore_db_instance_from_db_snapshot(
DBSnapshotIdentifier=snapshot_name,
DBInstanceIdentifier=db_id,
DBInstanceClass=rds_instance_class,
VpcSecurityGroupIds=secgroup,
DBSubnetGroupName=rds_subnet_groupname,
MultiAZ=False,
PubliclyAccessible=False,
CopyTagsToSnapshot=True
)
waiter = rds.get_waiter('db_instance_available')
waiter.wait(DBInstanceIdentifier=db_id)
# some other operation that expects that DB is up and running.
添加服务员是为了尝试正确等待 DB。不过,貌似服务员超时了。
在这种情况下,正确的服务员应该使用什么?
会不会是您的服务员实际上正在检查现有的数据库并查看它是否可用,然后才能根据上一个命令更新状态以恢复快照?
尝试设置 waiter.config.delay
and/or waiter.config.max_attempts
.
waiter = rds.get_waiter('db_instance_available')
waiter.config.delay = 123 # this is in seconds
waiter.config.max_attempts = 123
waiter.wait(DBInstanceIdentifier=db_id)
或
waiter = rds.get_waiter('db_instance_available')
waiter.wait(
DBClusterIdentifier=db_id
WaiterConfig={
'Delay': 123,
'MaxAttempts': 123
}
)
WaiterConfig (dict) A dictionary that provides parameters to control
waiting behavior.
Delay (integer) The amount of time in seconds to wait between
attempts. Default: 30
MaxAttempts (integer) The maximum number of attempts to be made.
Default: 60
我的 Lambda(Python 和 Boto3)中有以下代码:
rds.restore_db_instance_from_db_snapshot(
DBSnapshotIdentifier=snapshot_name,
DBInstanceIdentifier=db_id,
DBInstanceClass=rds_instance_class,
VpcSecurityGroupIds=secgroup,
DBSubnetGroupName=rds_subnet_groupname,
MultiAZ=False,
PubliclyAccessible=False,
CopyTagsToSnapshot=True
)
waiter = rds.get_waiter('db_instance_available')
waiter.wait(DBInstanceIdentifier=db_id)
# some other operation that expects that DB is up and running.
添加服务员是为了尝试正确等待 DB。不过,貌似服务员超时了。
在这种情况下,正确的服务员应该使用什么?
会不会是您的服务员实际上正在检查现有的数据库并查看它是否可用,然后才能根据上一个命令更新状态以恢复快照?
尝试设置 waiter.config.delay
and/or waiter.config.max_attempts
.
waiter = rds.get_waiter('db_instance_available')
waiter.config.delay = 123 # this is in seconds
waiter.config.max_attempts = 123
waiter.wait(DBInstanceIdentifier=db_id)
或
waiter = rds.get_waiter('db_instance_available')
waiter.wait(
DBClusterIdentifier=db_id
WaiterConfig={
'Delay': 123,
'MaxAttempts': 123
}
)
WaiterConfig (dict) A dictionary that provides parameters to control waiting behavior.
Delay (integer) The amount of time in seconds to wait between attempts. Default: 30
MaxAttempts (integer) The maximum number of attempts to be made. Default: 60