使用lambda函数(Python)创建DynamoDB表 - 错误
我在该表定义中定义了3个属性。 AgentID,AgentName,Agentrole。我想在AgentID(PartitionKey),Agentrole(范围键)上创建Keyschema。
在我的理解中,表可以具有10个属性。所有这10个属性不必成为按键的一部分。因为Keyschema用于识别唯一的记录。正确的?
它引发以下错误:
Response
{
"errorMessage": "An error occurred (ValidationException) when calling the
CreateTable operation: One or more parameter values were invalid: Number of attributes in
KeySchema does not exactly match number of attributes defined in AttributeDefinitions",
"errorType": "ClientError",
"requestId": "d8d07c59-f36c-4989-9ac2-6ada9d8f6521",
"stackTrace": [
" File \"/var/task/lambda_function.py\", line 8, in lambda_handler\n
response = client.create_table(\n",
" File \"/var/runtime/botocore/client.py\", line 391, in _api_call\n return
self._make_api_call(operation_name, kwargs)\n",
" File \"/var/runtime/botocore/client.py\", line 719, in _make_api_call\n
raise error_class(parsed_response, operation_name)\n"
]
}
import json
import boto3
client = boto3.client("dynamodb")
def lambda_handler(event, context):
response = client.create_table(
AttributeDefinitions=[
{
'AttributeName': 'agentId',
'AttributeType': 'N'
},
{
'AttributeName': 'agentRole',
'AttributeType': 'S'
},
{
'AttributeName': 'agentName',
'AttributeType': 'S'
}
],
TableName='CallCenterCallsTable,
KeySchema=[
{
'AttributeName': 'agentId',
'KeyType': 'HASH'
},
{
'AttributeName': 'agentRole',
'KeyType': 'RANGE'
}
],
BillingMode='PROVISIONED',
ProvisionedThroughput={
'ReadCapacityUnits': 1,
'WriteCapacityUnits': 1
}
)
print(response)
I have defined 3 attributes in that table definition. agentId, agentName, agentRole. I want to create KeySchema on agentId (partitionkey) , agentRole (range key).
In my understanding the table can have 10 attributes. All those 10 attributes don't have to be part of the KeySchema. Because Keyschema is used to identify unique records. Right?
It throws the following error:
Response
{
"errorMessage": "An error occurred (ValidationException) when calling the
CreateTable operation: One or more parameter values were invalid: Number of attributes in
KeySchema does not exactly match number of attributes defined in AttributeDefinitions",
"errorType": "ClientError",
"requestId": "d8d07c59-f36c-4989-9ac2-6ada9d8f6521",
"stackTrace": [
" File \"/var/task/lambda_function.py\", line 8, in lambda_handler\n
response = client.create_table(\n",
" File \"/var/runtime/botocore/client.py\", line 391, in _api_call\n return
self._make_api_call(operation_name, kwargs)\n",
" File \"/var/runtime/botocore/client.py\", line 719, in _make_api_call\n
raise error_class(parsed_response, operation_name)\n"
]
}
import json
import boto3
client = boto3.client("dynamodb")
def lambda_handler(event, context):
response = client.create_table(
AttributeDefinitions=[
{
'AttributeName': 'agentId',
'AttributeType': 'N'
},
{
'AttributeName': 'agentRole',
'AttributeType': 'S'
},
{
'AttributeName': 'agentName',
'AttributeType': 'S'
}
],
TableName='CallCenterCallsTable,
KeySchema=[
{
'AttributeName': 'agentId',
'KeyType': 'HASH'
},
{
'AttributeName': 'agentRole',
'KeyType': 'RANGE'
}
],
BillingMode='PROVISIONED',
ProvisionedThroughput={
'ReadCapacityUnits': 1,
'WriteCapacityUnits': 1
}
)
print(response)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从属性定义中删除
agentName
。参见属性定义的文档 :
您不在“键模式”或“索引”中使用
agentName
,因此不应包含在表定义中。 DynamoDB是示意性的。您只需要在创建时间定义哈希键和排序键即可。 DynamoDB不在乎您可能想插入表中的任何其他属性。Remove
agentName
from the Attribute definitions.See the documentation for Attribute Definitions:
You aren't using
agentName
in the key schema or indexes, so it shouldn't be included in the table definition. DynamoDB is schemaless. You only need to define the hash key and sort key at creation time. DynamoDB doesn't care about any other attributes you may want to insert into your table.