I'm learning DynamoDB.
I want to create a table with the following Primary Key:
- Partition key: name
- Sort key: creationDate
And with the following attributes:
- name (pk)
- address (sk)
- creationDate
- isActive
This is my TS interface (just in case it helps to describe what I want)
interface User {
readonly name: string;
readonly address: string;
readonly creationDate: Date;
readonly isActive: boolean;
}
I wrote the following template:
Resources:
myDynamoDBTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: 'name'
AttributeType: 'S'
- AttributeName: 'address'
AttributeType: 'S'
- AttributeName: 'creationDate'
AttributeType: 'S'
- AttributeName: 'isActive'
AttributeType: 'S'
KeySchema:
- AttributeName: 'name'
KeyType: HASH
- AttributeName: 'creationDate'
KeyType: RANGE
When I deploy it, it fails with the following error
One or more parameter values were invalid: Number of attributes in KeySchema does not exactly match number of attributes defined in AttributeDefinitions
I google it and found several answers but I still don't understand what's going and how can I have those attributes in my table (all items are going to have those attributes).
Is there a way I can do it? If so, what am I doing wrong? Thanks