使用SAM模板创建DynamoDB表时出错



我想使用SAM模板创建DynamoDB表,而且我是SAM模板的新手。我对HashRange没有更好的想法这是我的DynamoDB模板部分

MyDynamoDBTable:
Type: AWS::DynamoDB::Table
DeletionPolicy: Retain
Properties:
TableName: customerInformations
AttributeDefinitions:
- AttributeName: phoneNumber
AttributeType: S
- AttributeName: firstName
AttributeType: S
- AttributeName: lastName
AttributeType: S
- AttributeName: address
AttributeType: S
- AttributeName: email
AttributeType: S
KeySchema:
- AttributeName: phoneNumber
KeyType: HASH
- AttributeName: firstName
KeyType: RANGE
- AttributeName: lastName
KeyType: RANGE
- AttributeName: address
KeyType: RANGE
- AttributeName: email
KeyType: RANGE

这是我在创建表时得到的错误代码。

CREATE_FAILED       AWS::DynamoDB::Table        MyDynamoDBTable             Resource handler retur                                                               message: "1 validation
error detected: Value '[K
eySchemaElement(attribute
Name=phoneNumber,
keyType=HASH), KeySchemaE
lement(attributeName=firs
tName, keyType=RANGE), Ke
ySchemaElement(attributeN
ame=lastName,
keyType=RANGE), KeySchema
Element(attributeName=add
ress, keyType=RANGE), Key
SchemaElement(attributeNa
me=email,
keyType=RANGE)]' at
'keySchema' failed to
satisfy constraint:
Member must have length
less than or equal to 2
(Service: DynamoDb,
Status Code: 400, Request
ID: 2SRKQ9ETQUEGIC6GO0HHT
70JIJVV4KQNSO5AEMVJF66Q9A
SUAAJG)" (RequestToken: b
9b143a9-c010-f185-4811-93
a3b91f2e52,
HandlerErrorCode:
InvalidRequest)

如有任何帮助,我们将不胜感激。

您正试图创建一个具有4个Range键的表。Dynamo只支持一个Partition和一个Range键。在继续之前,您应该先查看文档。

示例解决方案:

MyDynamoDBTable:
Type: AWS::DynamoDB::Table
DeletionPolicy: Retain
Properties:
TableName: customerInformations
AttributeDefinitions:
- AttributeName: phoneNumber
AttributeType: S
- AttributeName: firstName
AttributeType: S
KeySchema:
- AttributeName: phoneNumber
KeyType: HASH
- AttributeName: firstName
KeyType: RANGE

最新更新