Создать таблицу DynamoDB в бессерверном yml-файле - PullRequest
0 голосов
/ 03 августа 2020

Я собираюсь создать таблицу в файле 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. Можно ли создать такую ​​таблицу? Разве я не могу создать таблицу с атрибутами, не включенными ни в один индекс?

1 Ответ

2 голосов
/ 03 августа 2020

Вы должны включить ключи в определения атрибутов.

  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
...