Python Boto3 put_item在使用本地 dynamodb 容器时失败



我正在使用本地dynamodb docker容器测试boto,在将新项目放入表中时出现此错误。表存在。

from __future__ import print_function # Python 2/3 compatibility
import boto3
import os
os.environ["AWS_ACCESS_KEY_ID"] = "localaccesskey"
os.environ["AWS_SECRET_ACCESS_KEY"] = "password"
conn = boto3.resource('dynamodb', aws_access_key_id="localaccesskey",  aws_secret_access_key="password", region_name='eu-west-1', endpoint_url="http://localhost:8000")
print(list(conn.tables.all()))

table = conn.Table('Movies')
table.put_item(
   Item={
        'username': 'janedoe',
        'first_name': 'Jane',
        'last_name': 'Doe',
        'age': 25,
        'account_type': 'standard_user',
    }
)

错误:

/usr/bin/python2.7 /home/kshk/PycharmProjects/Skulldogo/eli.py
[dynamodb.Table(name=u'Movies'), dynamodb.Table(name=u'devApiConfig'), dynamodb.Table(name=u'devApiKeys'), dynamodb.Table(name=u'devObjectCache'), dynamodb.Table(name=u'devSessionCache'), dynamodb.Table(name=u'test'), dynamodb.Table(name=u'test1'), dynamodb.Table(name=u'test10')]
Traceback (most recent call last):
  File "/home/kshk/PycharmProjects/Skulldogo/eli.py", line 52, in <module>
    'account_type': 'standard_user',
  File "/usr/lib/python2.7/site-packages/boto3/resources/factory.py", line 518, in do_action
    response = action(self, *args, **kwargs)
  File "/usr/lib/python2.7/site-packages/boto3/resources/action.py", line 83, in __call__
    response = getattr(parent.meta.client, operation_name)(**params)
  File "/usr/lib/python2.7/site-packages/botocore/client.py", line 258, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/usr/lib/python2.7/site-packages/botocore/client.py", line 548, in _make_api_call
    raise ClientError(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the PutItem operation: One of the required keys was not given a value

有什么想法吗???

DynamoDB 在创建新记录时不会自动生成 ID。确保提供哈希键。

哦,定义时还有范围键。

相关内容

  • 没有找到相关文章

最新更新