【发布时间】:2018-05-03 06:26:51
【问题描述】:
我的 serverless.yml 中有一些类似这样的代码。
resources:
Resources:
uploadBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: ${self:service}-${self:custom.stage}-uploads
visitsTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:custom.visitsTable}
AttributeDefinitions:
- AttributeName: userId
AttributeType: S
- AttributeName: visitId
AttributeType: S
- AttributeName: comments
AttributeType: S
- AttributeName: attachments
AttributeType: S
- AttributeName: ph
AttributeType: N
- AttributeName: ch
AttributeType: N
KeySchema:
- AttributeName: userId
KeyType: HASH
- AttributeName: visitId
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
我的目标是创建一个具有主键 userId 的表,排序键 visitId 并具有 cmets、附件、ph 和 ch 的字段。当我尝试sls deploy 时,出现以下错误。
无服务器错误 ----------------------------------------
发生错误:visitsTable - Property AttributeDefinitions 与表的 KeySchema 和二级索引不一致。
我在这里做错了什么?
编辑:我尝试的另一次尝试
resources:
Resources:
uploadBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: ${self:service}-${self:custom.stage}-uploads
visitsTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:custom.visitsTable}
AttributeDefinitions:
- AttributeName: userId
AttributeType: S
- AttributeName: visitId
AttributeType: S
KeySchema:
- AttributeName: userId
KeyType: HASH
- AttributeName: visitId
KeyType: RANGE
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
【问题讨论】:
-
您提到了 visitid 作为范围键(排序)。但是在您的 YAML 配置中,它被称为哈希键。
- AttributeName: visitId KeyType: RANGE -
我想知道是否应该输入范围,但不确定这是否是“排序”。
-
我试过放范围但同样的错误。 (我把它全部大写,RANGE),就像你的例子一样,还有其他想法吗?
-
您正在尝试创建一个表。所以删除除 Key Schema 和 Indexes 之外的属性。从 AWS DOCS 可以清楚地看出,AttributeDefinitions 是一个属性数组,用于描述表和索引的关键架构。更多docs.aws.amazon.com/amazondynamodb/latest/APIReference/…
-
很有趣,那会是什么样子呢?我还需要 2 个 Keyschema 值吗?
标签: amazon-web-services amazon-dynamodb serverless-framework