1

I want to set some Attributes for my DynamoDB table in Cloudformation, but I get this error:

Code:

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

Error:

E3039 The set of Attributes in AttributeDefinitions: ['Email', 'Surname', 'UserId', 'Username'] and KeySchemas: ['UserId'] must match at Resources/User/Properties

vasil001
  • 2,501
  • 4
  • 8
  • 22
  • 3
    Only attributes used as keys have to be declared upfront – Pat Myron Jan 19 '21 at 22:52
  • Does this answer your question? [CloudFormation insists my DynamoDB creation JSON is invalid .. but I can't see how](https://stackoverflow.com/questions/38142870/cloudformation-insists-my-dynamodb-creation-json-is-invalid-but-i-cant-see-h) – Pat Myron Jan 19 '21 at 22:54

2 Answers2

2

documentation

The partition key of an item is also known as its hash attribute. The term "hash attribute" derives from DynamoDB's usage of an internal hash function to evenly distribute data items across partitions, based on their partition key values.

The sort key of an item is also known as its range attribute. The term "range attribute" derives from the way DynamoDB stores items with the same partition key physically close together, in sorted order by the sort key value.

here What is Hash and Range Primary Key? you can find a thorough answer.

samtoddler
  • 8,463
  • 2
  • 26
  • 21
1

I did the following, and it seems to work. But I don’t understand the difference between the HASH and RANGE key types. Am I creating 4 columns and a Primary Key UserId, here?

    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
ib.
  • 27,830
  • 11
  • 80
  • 100
vasil001
  • 2,501
  • 4
  • 8
  • 22