Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boto : ResourceNotFoundException Dynamodb

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

code

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?

like image 815
user3089927 Avatar asked Aug 03 '16 01:08

user3089927


2 Answers

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.

like image 57
Stephen_D_Lewis Avatar answered Nov 15 '22 22:11

Stephen_D_Lewis


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!

like image 10
cryanbhu Avatar answered Nov 15 '22 22:11

cryanbhu