【问题标题】:Create DynamoDB table in serverless yml file在无服务器 yml 文件中创建 DynamoDB 表
【发布时间】:2020-08-03 00:39:19
【问题描述】:

我将在 yml 文件中创建表。当我写如下时,首先它是成功创建的。

  UsersTable:
  Type: AWS::DynamoDB::Table
  Properties:
    TableName: users
    AttributeDefinitions:
      - AttributeName: user_id
        AttributeType: S
    KeySchema:
      - AttributeName: user_id
        KeyType: HASH
    ProvisionedThroughput:
      ReadCapacityUnits: 5
      WriteCapacityUnits: 5

但我需要更多的属性,所以我改变如下。

  UsersTable:
  Type: AWS::DynamoDB::Table
  Properties:
    TableName: users
    AttributeDefinitions:
      - AttributeName: user_id
        AttributeType: S
      - AttributeName: email_lower_case
        AttributeType: S
      - AttributeName: book_id
        AttributeType: S
      - AttributeName: book_amount
        AttributeType: S  
    KeySchema:
      - AttributeName: user_id
        KeyType: HASH
    ProvisionedThroughput:
      ReadCapacityUnits: 5
      WriteCapacityUnits: 5

但它显示这样的错误。

An error occurred: UsersTable - One or more parameter values were invalid: Number of attributes in KeySchema does not exactly match number of attributes defined in AttributeDefinitions

我不想使用其他 KeySchema。是否可以创建这样的表? 我不能用不包含在任何索引中的属性创建表吗?

【问题讨论】:

  • 除了哈希和范围键之外,您没有定义任何属性。您的程序可以在插入或更新期间创建任意数量的属性。

标签: node.js amazon-web-services amazon-dynamodb yaml


【解决方案1】:

您必须在属性定义中包含键。

  UsersTable:
  Type: AWS::DynamoDB::Table
  Properties:
    TableName: users
    AttributeDefinitions:
      - AttributeName: user_id
        AttributeType: S

      - AttributeName: bitwage_user_id
        AttributeType: S
      - AttributeName: email_lower_case
        AttributeType: S
      - AttributeName: book_id
        AttributeType: S
      - AttributeName: book_amount
        AttributeType: S  
    KeySchema:
      - AttributeName: user_id
        KeyType: HASH
    ProvisionedThroughput:
      ReadCapacityUnits: 5
      WriteCapacityUnits: 5

【讨论】:

    猜你喜欢
    • 2023-01-07
    • 1970-01-01
    • 2018-05-12
    • 1970-01-01
    • 1970-01-01
    • 2018-12-18
    • 2019-04-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多