Reputation: 3895
I have a table - user_details that has 500 read/write capacity + 500 on indexes as well with over 5k items, currently. I am querying the table based on username and it seems to be giving me "ResourceNotFoundException" all the time -
ClientError: An error occurred (ResourceNotFoundException) when calling the Query operation: Requested resource not found
user_details_db_client = boto3.resource(dynamo_string, us_west_2).Table(user_details)
def if_details_exists_for_user(username,region = None):
time.sleep(1)
result = None
try:
if region:
#result = user_details_db_client.scan(FilterExpression=Attr('username').eq(username) & Attr('region').eq(region))
result = user_details_db_client.query(IndexName = "username-index", KeyConditionExpression = Key('username').eq(username), FilterExpression=Attr('region').eq(region))
else:
result = user_details_db_client.query(IndexName = "username-index", KeyConditionExpression = Key('username').eq(username))
#result = user_details_db_client.scan(FilterExpression=Attr('username').eq(username))
if result and result['Items']:
logger.info("User {} exists in user_details table for region {}".format(username,region))
return (True, result['Items'])
else:
return (False, FAILED)
except Exception:
logger.error("Caught exception : {} while getting data from user_details table".format(traceback.format_exc()))
return (False, FAILED)
I can confirm that table exists and other scripts are using it. I tried finding on doc or somewhere but could not get a concrete reasoning.
How can I debug this? or I am missing something altogether?
Upvotes: 8
Views: 32961
Reputation: 5254
i hit this error because I was connecting to the wrong region, so make sure to connect to the correct region where your table is!
Upvotes: 12
Reputation: 359
I would check to see if the table actually exists. The boto3 library has a surprising behavior here. This line:
user_details_db_client = boto3.resource(dynamo_string, us_west_2).Table(user_details)
will succeed even if the table doesn't exist. (Naming wise, note also that this is a "resource", not a "client").
To see which tables exist, try looking at the available subresources, or using the "list_tables" command
boto3.resource(dynamo_string, us_west_2).get_available_subresources()
boto3.client(dynamo_string, us_west_2).list_tables()
There you will be able to see if the table you are looking for exists.
Upvotes: 16