Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import specific error from boto?

Tags:

boto3

I am getting this exception (printing the class for debugging) when running my code:

An error occurred (DBInstanceNotFound) when calling the DescribeDBInstances operation: DBInstance <instance name> not found.
<class 'botocore.errorfactory.DBInstanceNotFoundFault'>

I would like to handle the exception properly like this:

from botocore.exceptions import DBInstanceNotFoundFault
from botocore.errorfactory import DBInstanceNotFoundFault
try:
    <fetch info about db instance>
except DBInstanceNotFoundFault as e:
    <handle error>

Unfortunately DBInstanceNotFoundFault does neither exist in botocore.exceptions nor in botocore.errorfactory. I've cloned boto3 as well as botocore and grep'd for DBInstanceNotFoundFault but just can't find it.

How can I import it?

like image 753
kev Avatar asked Jan 03 '18 23:01

kev


1 Answers

For boto3 exceptions, you don't actually import the error - rather you access it through the client. Check this out: https://github.com/boto/boto3/issues/1195#issuecomment-317108970

import boto3
rds = boto3.client('rds')
try:
    ...
except rds.exceptions.DBInstanceNotFoundFault:
    ...
like image 113
Karlie Verkest De Young Avatar answered Sep 29 '22 22:09

Karlie Verkest De Young