如何捕获此boto错误botocore.errorfactory.DBInstanceNotFoundFault
这是我的python3代码:
import boto3
import botocore.exceptions
import botocore.errorfactory
clientrds = boto3.client('rds')
rdsInstances = ['prod-rds']
for rds in rdsInstances :
rds_response = clientrds.describe_db_instances(DBInstanceIdentifier=rds)
DBInstanceStatus = (rds_response["DBInstances"][0]["DBInstanceStatus"])
if DBInstanceStatus == "stopped" :
print(rds," Switched On ")
start_rds_response = clientrds.start_db_instance(DBInstanceIdentifier=rds)控制台输出/错误:
Traceback (most recent call last):
File "/home/rds.py", line 11, in <module>
rds_response = clientrds.describe_db_instances(DBInstanceIdentifier=rds)
File "/home/.local/lib/python3.8/site-packages/botocore/client.py", line 391, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/home/.local/lib/python3.8/site-packages/botocore/client.py", line 719, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.errorfactory.DBInstanceNotFoundFault: An error occurred (DBInstanceNotFound) when calling the DescribeDBInstances operation: DBInstance prod-rds not found.发布于 2022-04-10 13:17:47
能够使用botocore.exceptions处理请求
for rds in rdsInstances :
try :
start_rds_response = clientrds.start_db_instance(DBInstanceIdentifier=rds) #RDS.instance.start
except botocore.errorfactory.ClientError as error:
if error.response['Error']['Code'] == 'DBInstanceNotFound':
print("DBInstanceNotFound")参考文献:链接
https://stackoverflow.com/questions/71809385
复制相似问题