【问题标题】:The set of Attributes in AttributeDefinitions and KeySchemas must match at Resources/DynamoDB/PropertiesAttributeDefinitions 和 KeySchemas 中的属性集必须在 Resources/DynamoDB/Properties 匹配
【发布时间】:2021-04-24 02:59:02
【问题描述】:

我想在 Cloudformation 中为我的 DynamoDB 表设置一些属性,但出现此错误:

代码:

DynamoDB:
Type: AWS::DynamoDB::Table
Properties:
  AttributeDefinitions:
    - AttributeName: UserId
      AttributeType: S
    - AttributeName: Username
      AttributeType: S
    - AttributeName: Surname
      AttributeType: S
    - AttributeName: Email
      AttributeType: S
  BillingMode: PAY_PER_REQUEST
  KeySchema:      
    - AttributeName: UserId
      KeyType: HASH

错误:

E3039 AttributeDefinitions 中的属性集:['Email', 'Surname', 'UserId', 'Username'] 和 KeySchemas: ['UserId'] 必须在 Resources/User/Properties 匹配

【问题讨论】:

标签: amazon-web-services nosql amazon-dynamodb amazon-cloudformation


【解决方案1】:

我做了以下,它似乎工作。但我不明白HASHRANGE 键类型之间的区别。我在这里创建 4 列和一个主键 UserId 吗?

    DynamoDB:
     Type: AWS::DynamoDB::Table
     Properties:
      AttributeDefinitions:
        - AttributeName: "UserId"
          AttributeType: "S"
        - AttributeName: Username
          AttributeType: S
        - AttributeName: Surname
          AttributeType: S
        - AttributeName: Email
          AttributeType: S                    
      BillingMode: PAY_PER_REQUEST
      KeySchema:  
        - AttributeName: UserId
          KeyType: HASH
        - AttributeName: Username
          KeyType: RANGE
        - AttributeName: Surname
          KeyType: RANGE
        - AttributeName: Email
          KeyType: RANGE

【讨论】:

    【解决方案2】:

    documentation

    项目的分区键也称为其哈希属性。术语“哈希属性”源自 DynamoDB 使用内部哈希函数根据分区键值在分区之间均匀分布数据项。

    项目的排序键也称为其范围属性。术语“范围属性”源自 DynamoDB 将具有相同分区键的项目存储在一起的方式,这些项目在物理上靠得很近,按排序键值排序。

    在这里What is Hash and Range Primary Key?你可以找到一个彻底的答案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-01-23
      • 1970-01-01
      • 2018-10-05
      • 2015-09-01
      • 1970-01-01
      • 2012-06-05
      • 1970-01-01
      相关资源
      最近更新 更多