1

I am using Dynamodb2 with boto. I have a schema defined as following:

schema=[
                HashKey('id', data_type=NUMBER),

       ]

To insert into the id field I have generated a random id using Python's uuid with the command uuid.uuid1() as follows:

id = int(uuid.uuid1())

But when I try to insert ID into the table, I get the following error:

{
  "error_message": "BotoClientError: Inexact numeric for `144095370333333371533171708191171526873`\nNone",

  "traceback": "Traceback (most recent call last):\n\n  File \"/usr/local/lib/python2.7/dist-packages/tastypie/resources.py\", line 195, in wrapper\n    response = callback(request, *args, **kwargs)\n\n  File \"/usr/local/lib/python2.7/dist-packages/tastypie/resources.py\", line 426, in dispatch_list\n    return self.dispatch('list', request, **kwargs)\n\n  File \"/usr/local/lib/python2.7/dist-packages/tastypie/resources.py\", line 458, in dispatch\n    response = method(request, **kwargs)\n\n  File \"/usr/local/lib/python2.7/dist-packages/tastypie/resources.py\", line 1320, in post_list\n    updated_bundle = self.obj_create(bundle, **self.remove_api_resource_names(kwargs))\n\n  File \"/home/sudip/phunka/projects/freelance/2youtubestats/ViewsApp/myapi.py\", line 186, in obj_create\n    returned_id = form.save()\n\n  File \"/home/sudip/phunka/projects/freelance/2youtubestats/ViewsApp/forms.py\", line 88, in save\n    save_single_video(final_data)\n\n  File \"/home/sudip/phunka/projects/freelance/2youtubestats/ViewsApp/dynamo_operations.py\", line 141, in save_single_video\n    main_table.put_item(data=data)\n\n  File \"/usr/local/lib/python2.7/dist-packages/boto/dynamodb2/table.py\", line 491, in put_item\n    return item.save(overwrite=overwrite)\n\n  File \"/usr/local/lib/python2.7/dist-packages/boto/dynamodb2/items.py\", line 439, in save\n    final_data = self.prepare_full()\n\n  File \"/usr/local/lib/python2.7/dist-packages/boto/dynamodb2/items.py\", line 320, in prepare_full\n    final_data[key] = self._dynamizer.encode(value)\n\n  File \"/usr/local/lib/python2.7/dist-packages/boto/dynamodb/types.py\", line 234, in encode\n    return {dynamodb_type: encoder(attr)}\n\n  File \"/usr/local/lib/python2.7/dist-packages/boto/dynamodb/types.py\", line 250, in _encode_n\n    raise DynamoDBNumberError(msg)\n\nDynamoDBNumberError: BotoClientError: Inexact numeric for `144095370333333371533171708191171526873`\nNone\n"
}

Am I missing out on something?

Sudip Kafle
  • 4,286
  • 5
  • 36
  • 49

1 Answers1

3

Numbers in DynamoDB can have at most 38 digits (AWS docs).

id = int(uuid.uuid1()/4)

That should give you a random id that DynamoDB will hold.

bslawski
  • 600
  • 1
  • 9
  • 22