gpt4 book ai didi

amazon-web-services - 带排序键的无服务器框架Dynamo DB表资源定义

转载 作者:行者123 更新时间:2023-12-04 00:14:19 24 4
gpt4 key购买 nike

目前,在我的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进行排序,并具有用于注释,附件,ph和ch的字段。当我尝试 sls deploy时,出现以下错误。

无服务器错误---------------------------------------

发生错误:visitsTable-属性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

最佳答案

AWS DynamoDb是一个NO-SQL类型数据库,无需在创建表期间定义所有键。从AWS文档中还可以清楚地看到,在Attribute Definition中,您必须指定Key模式和索引。

An array of attributes that describe the key schema for the table and indexes.



请按以下方式编辑您的代码
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

有关更多 CreateTable

关于amazon-web-services - 带排序键的无服务器框架Dynamo DB表资源定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47385177/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com