I am trying to create an AWS DynamoDB table using AWS CloudFormation,
I am getting an error while creating the same.
Previously I had specified all the columns of the table that I wanted,
But it seemed like AttributeDefinitions and KeySchema Properties need to somehow match, not sure though.
I narrowed down to just 2 columns which are must have in my table,
ie. user_id and expiry
,
The user_id being the Primary Key and expiry being the column used for TTL purpose.
I am still getting the following error though -
Property AttributeDefinitions is inconsistent with the KeySchema of the table and the secondary indexes
Following is the snippet of my template where I'm getting an issue as per CloudFormation StatusReason -
userExpiry:
Type: 'AWS::DynamoDB::Table'
Properties:
TableName: !Join ['_', [!Ref "prefix",'user_expiry'] ]
AttributeDefinitions:
-
AttributeName: 'expiry'
AttributeType: 'N'
-
AttributeName: 'user_id'
AttributeType: 'S'
KeySchema:
- AttributeName: "user_id"
KeyType: "HASH"
TimeToLiveSpecification:
AttributeName: "expiry"
Enabled: true
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
Tags:
-
Key: 'Project'
Value: !Ref "ProjectName"
-
Key: 'Environment'
Value: !Ref "ResourceEnvironment"
I am following this reference Doc -
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html