Moto: creating mock dynamodb table fails with TypeError: list indices must be integers, not unicode

Created on 4 Dec 2017  路  3Comments  路  Source: spulec/moto

Python 2.7.10 (yes, the project needs to upgrade)
moto==1.1.25
boto3==1.4.8

The following code returns an error (pasted below).

from moto import mock_dynamodb
import boto3


@mock_dynamodb
def testit():
    dynamo = boto3.client('dynamodb', region_name='us-west-2')
    dynamo.create_table(TableName='economy-cloud-users',
                        AttributeDefinitions=[{'AttributeName': 'user_name',
                                               'AttributeType': 'S'}],
                        KeySchema=[{'KeyType': 'HASH', 'AttributeName': 'user_name'}],
                        ProvisionedThroughput={'ReadCapacityUnits': 5,
                                               'WriteCapacityUnits': 5})


if __name__ == '__main__':
    testit()

Output:

Traceback (most recent call last):
  File "bug.py", line 19, in <module>
    testit()
  File "/Users/dtenenba/envs/economy-cloud-MYowzdHw/lib/python2.7/site-packages/moto/core/models.py", line 71, in wrapper
    result = func(*args, **kwargs)
  File "bug.py", line 15, in testit
    'WriteCapacityUnits': 5})
  File "/Users/dtenenba/envs/economy-cloud-MYowzdHw/lib/python2.7/site-packages/botocore/client.py", line 314, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/Users/dtenenba/envs/economy-cloud-MYowzdHw/lib/python2.7/site-packages/botocore/client.py", line 599, in _make_api_call
    operation_model, request_dict)
  File "/Users/dtenenba/envs/economy-cloud-MYowzdHw/lib/python2.7/site-packages/botocore/endpoint.py", line 143, in make_request
    return self._send_request(request_dict, operation_model)
  File "/Users/dtenenba/envs/economy-cloud-MYowzdHw/lib/python2.7/site-packages/botocore/endpoint.py", line 172, in _send_request
    success_response, exception):
  File "/Users/dtenenba/envs/economy-cloud-MYowzdHw/lib/python2.7/site-packages/botocore/endpoint.py", line 265, in _needs_retry
    caught_exception=caught_exception, request_dict=request_dict)
  File "/Users/dtenenba/envs/economy-cloud-MYowzdHw/lib/python2.7/site-packages/botocore/hooks.py", line 227, in emit
    return self._emit(event_name, kwargs)
  File "/Users/dtenenba/envs/economy-cloud-MYowzdHw/lib/python2.7/site-packages/botocore/hooks.py", line 210, in _emit
    response = handler(**kwargs)
  File "/Users/dtenenba/envs/economy-cloud-MYowzdHw/lib/python2.7/site-packages/botocore/retryhandler.py", line 183, in __call__
    if self._checker(attempts, response, caught_exception):
  File "/Users/dtenenba/envs/economy-cloud-MYowzdHw/lib/python2.7/site-packages/botocore/retryhandler.py", line 251, in __call__
    caught_exception)
  File "/Users/dtenenba/envs/economy-cloud-MYowzdHw/lib/python2.7/site-packages/botocore/retryhandler.py", line 269, in _should_retry
    return self._checker(attempt_number, response, caught_exception)
  File "/Users/dtenenba/envs/economy-cloud-MYowzdHw/lib/python2.7/site-packages/botocore/retryhandler.py", line 317, in __call__
    caught_exception)
  File "/Users/dtenenba/envs/economy-cloud-MYowzdHw/lib/python2.7/site-packages/botocore/retryhandler.py", line 223, in __call__
    attempt_number, caught_exception)
  File "/Users/dtenenba/envs/economy-cloud-MYowzdHw/lib/python2.7/site-packages/botocore/retryhandler.py", line 359, in _check_caught_exception
    raise caught_exception
TypeError: list indices must be integers, not unicode

The same error does not happen in real AWS (if I comment out the decorator), it just creates the table.

Most helpful comment

You're using boto3. Use @mock_dynamodb2.

All 3 comments

You're using boto3. Use @mock_dynamodb2.

That did it, thanks.

I believe when to use @mock_dynamodb2 should be mentioned more clearly in the docs

Was this page helpful?
0 / 5 - 0 ratings