【发布时间】:2020-01-18 04:50:52
【问题描述】:
调用我的 lambda 技能时出现以下错误
ClientError: An error occurred (ValidationException)
when calling the CreateTable operation: 1 validation error detected:
Value '[com.amazonaws.dynamodb.v20120810.KeySchemaElement@2273ace6,
com.amazonaws.dynamodb.v20120810.KeySchemaElement@4d13ab9,
com.amazonaws.dynamodb.v20120810.KeySchemaElement@115e22b2]' at
'keySchema' failed to satisfy constraint: Member must have length less than or equal to 2
代码如下:
def write_values_to_db(ddid, token, intent):
pid = ...
dynamodb_client = boto3.client('dynamodb')
try:
response = dynamodb_client.create_table(
AttributeDefinitions=[
{
'AttributeName': 'pid',
'AttributeType': 'S',
},
{
'AttributeName': 'ddid',
'AttributeType': 'S',
},
{
'AttributeName': 'token',
'AttributeType': 'S',
},
],
KeySchema=[
{
'AttributeName': 'pid',
'KeyType': 'HASH',
},
{
'AttributeName': 'ddid',
'KeyType': 'RANGE',
},
{
'AttributeName': 'token',
'KeyType': 'RANGE',
},
],
ProvisionedThroughput={
'ReadCapacityUnits': 5,
'WriteCapacityUnits': 5,
},
TableName='Values',
)
except dynamodb_client.exceptions.ResourceInUseException:
dynamodb_client.put_item(
TableName='Values',
Item={
'pid': pid,
'ddid': ddid,
'token': token
}
)
根据我的仪表板,错误出现在TableName='Values' 行。我正在关注一个教程,只更改了某些内容,所以我不明白为什么这不起作用。我无法在本地环境中进行测试,因为我有区域/凭据问题。
【问题讨论】:
-
DynamoDB 需要一个哈希键,并且主键中不超过一个范围键,不是吗?
标签: lambda amazon-dynamodb boto3