Amazon dynamodb dynamodb如何在serverless.yml中定义无键模式?

Amazon dynamodb dynamodb如何在serverless.yml中定义无键模式?,amazon-dynamodb,serverless-framework,serverless,Amazon Dynamodb,Serverless Framework,Serverless,我尝试在我的无服务器aws lambda中应用dynamodb。 我的文件如下: resources: Resources: StoreDynamoDbTable: Type: 'AWS::DynamoDB::Table' DeletionPolicy: Retain Properties: AttributeDefinitions: - AttributeName: id Attribu

我尝试在我的无服务器aws lambda中应用dynamodb。 我的文件如下:

resources:
  Resources:
    StoreDynamoDbTable:
      Type: 'AWS::DynamoDB::Table'
      DeletionPolicy: Retain
      Properties:
        AttributeDefinitions:
          - AttributeName: id
            AttributeType: S
          - AttributeName: lat
            AttributeType: N 
          - AttributeName: lng
            AttributeType: N
        KeySchema:
          - AttributeName: id
            KeyType: HASH
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        TableName: ${self:provider.environment.TableStore}
我尝试将lat和lng作为storeTable的属性,只是属性而不是键模式,但是每个store元素都应该具有这些属性

但有一个错误:

出现错误:StoreDynamoDbTable-属性AttributeDefinitions 与表和辅助表的键模式不一致 索引


如何使lat和lng只是mast属性,而不是索引的关键元素?

DynamoDB要求您只声明构成关键模式的属性。()

如果
id
是用于构成密钥架构的唯一属性,则您的资源应如下所示:

resources:
  Resources:
    StoreDynamoDbTable:
      Type: 'AWS::DynamoDB::Table'
      DeletionPolicy: Retain
      Properties:
        AttributeDefinitions:
          - AttributeName: id
            AttributeType: S
        KeySchema:
          - AttributeName: id
            KeyType: HASH
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        TableName: ${self:provider.environment.TableStore}
resources:
  Resources:
    StoreDynamoDbTable:
      Type: 'AWS::DynamoDB::Table'
      DeletionPolicy: Retain
      Properties:
        AttributeDefinitions:
          - AttributeName: id
            AttributeType: S
          - AttributeName: date
            AttributeType: S
        KeySchema:
          - AttributeName: id
            KeyType: HASH
          - AttributeName: date
            KeyType: RANGE
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        TableName: ${self:provider.environment.TableStore}
DynamoDB不关心其他属性。插入数据后,DynamoDB将检测新属性,而无需在模式中声明它们。这就是非关系数据库的全部要点


此外,如果您希望在密钥架构中使用日期作为排序密钥,可以使用如下内容:

resources:
  Resources:
    StoreDynamoDbTable:
      Type: 'AWS::DynamoDB::Table'
      DeletionPolicy: Retain
      Properties:
        AttributeDefinitions:
          - AttributeName: id
            AttributeType: S
        KeySchema:
          - AttributeName: id
            KeyType: HASH
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        TableName: ${self:provider.environment.TableStore}
resources:
  Resources:
    StoreDynamoDbTable:
      Type: 'AWS::DynamoDB::Table'
      DeletionPolicy: Retain
      Properties:
        AttributeDefinitions:
          - AttributeName: id
            AttributeType: S
          - AttributeName: date
            AttributeType: S
        KeySchema:
          - AttributeName: id
            KeyType: HASH
          - AttributeName: date
            KeyType: RANGE
        ProvisionedThroughput:
          ReadCapacityUnits: 1
          WriteCapacityUnits: 1
        TableName: ${self:provider.environment.TableStore}
密钥架构始终至少有一个分区(
HASH
)密钥,并且可以选择有一个排序(
RANGE
)密钥