Reputation: 40654
I have doubled checked that the item exists in the dynamodb table. id
is the default hash key.
I want to retrieve the content by using the main
function in this code:
import boto.dynamodb2
from boto.dynamodb2 import table
table='doc'
region='us-west-2'
aws_access_key_id='YYY'
aws_secret_access_key='XXX'
def get_db_conn():
return boto.dynamodb2.connect_to_region(
region,
aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key)
def get_table():
return table.Table(table, get_db_conn())
def main():
tbl = get_table()
doc = tbl.get_item(id='4d7a73b6-2121-46c8-8fc2-54cd4ceb2a30')
print doc.keys()
However I get this exception instead:
File "scripts/support/find_doc.py", line 31, in <module>
main()
File "scripts/support/find_doc.py", line 33, in main
doc = tbl.get_item(id='4d7a73b6-2121-46c8-8fc2-54cd4ceb2a30')
File "/Users/antkong/project-ve/lib/python2.7/site-packages/boto/dynamodb2/table.py", line 504, in get_item
consistent_read=consistent
File "/Users/antkong/project-ve/lib/python2.7/site-packages/boto/dynamodb2/layer1.py", line 1065, in get_item
body=json.dumps(params))
File "/Users/antkong/project-ve/lib/python2.7/site-packages/boto/dynamodb2/layer1.py", line 2731, in make_request
retry_handler=self._retry_handler)
File "/Users/antkong/project-ve/lib/python2.7/site-packages/boto/connection.py", line 953, in _mexe
status = retry_handler(response, i, next_sleep)
File "/Users/antkong/project-ve/lib/python2.7/site-packages/boto/dynamodb2/layer1.py", line 2774, in _retry_handler
data)
boto.exception.JSONResponseError: JSONResponseError: 400 Bad Request
{u'message': u'Requested resource not found', u'__type': u'com.amazonaws.dynamodb.v20120810#ResourceNotFoundException'}
Why I am getting this error message?
I am using boto
version 2.34
Upvotes: 2
Views: 4610
Reputation: 809
I was getting this error because I was connecting to the wrong region.
To check your table region, go to overview tab of your table and scroll down to Amazon Resource Name (ARN) field.
My ARN starts with arn:aws:dynamodb:us-east-2:. Here 'us-east-2' is the region I need to pass while initiating the boto3 client.
Upvotes: 0
Reputation: 2626
If you have a range key you have to specify in the get_item, like so:
get_item(timestamp=Decimal('1444232509'), id='HASH_SHA1')
Here on my table Packages I have an index (id) and a range key (timestamp).
Upvotes: 1
Reputation: 40654
The problem is in this code:
def get_table():
return table.Table(table, get_db_conn())
It should be
def get_table():
return table.Table(table, connection=get_db_conn())
Note the connection
named parameter
Upvotes: 1