I'm new to DynamoDB (and NoSQL databases in general) so this is a pretty basic question.
Am working with existing code where a DynamoDB table is created via CloudFormation with YAML similar to the following:
MyDynamoDBTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: MyDynamoDBTable
AttributeDefinitions:
- AttributeName: Id
AttributeType: S
KeySchema:
- AttributeName: Id
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
The above just defines an Id column and no other attributes - but then in the code, further attributes (strings named Type and Payload) are always used when adding new items.
Have previously only worked with relational databases so this paradigm of adding attributes that aren't in a schema feels a bit alien. My question is would it ever be appropriate to include other attributes in the table definition that aren't part of the primary key? E.g. adding the following attributes to the AttributeDefinitions section:
- AttributeName: Type
AttributeType: S
- AttributeName: Payload
AttributeType: S
Would it be better to do this if I know up-front that such attributes will always be present for all items? Or is it better to be minimalist and only define a primary key and nothing else to allow for complete flexibility? (But if this always the best practice, why does the table definition allow you to do otherwise?)