Reputation: 139
I'm trying to build a template for each of my tables and I'm testing it with one table. However, I'm getting this error and I have no idea on how to fix it: One or more parameter values were invalid: Number of attributes in KeySchema does not exactly match number of attributes defined in AttributeDefinitions (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: NRTF448TGFEUGUB3H5UH37AGHBVV4KQNSO5AEMVJF66Q9ASUAAJG; Proxy: null)
The template that I'm using is this one:
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Resources" : {
"myddbtable": {
"Type" : "AWS::DynamoDB::Table",
"Properties" : {
"AttributeDefinitions" : [
{
"AttributeName": "phoneNumber",
"AttributeType": "S"
},
{
"AttributeName": "fname",
"AttributeType": "S"
},
{
"AttributeName": "lname",
"AttributeType": "S"
}
],
"BillingMode" : "PAY_PER_REQUEST",
"KeySchema" : [
{
"AttributeName" : "phoneNumber",
"KeyType": "HASH"
}
],
"TableName" : "UserTable2"
}
}
}
}
I tried putting the fname and the lname attributes on the KeySchema section with a KeyType of Range
and it didn't work either, any ideas?
Upvotes: 1
Views: 776
Reputation: 10333
As DynamoDB is schema less, we can add any attributes when creating/updating individual records. Hence when creating DynamoDB tables, we only need to define attributes which are part of primary index or global secondary index.
In this case, table has only primary key of phoneNumber
. We need to remove two other attributes fname
and 'lname` from definition
{
"AWSTemplateFormatVersion": "2010-09-09",
"Resources": {
"myddbtable": {
"Type": "AWS::DynamoDB::Table",
"Properties": {
"AttributeDefinitions": [
{
"AttributeName": "phoneNumber",
"AttributeType": "S"
}
],
"BillingMode": "PAY_PER_REQUEST",
"KeySchema": [
{
"AttributeName": "phoneNumber",
"KeyType": "HASH"
}
],
"TableName": "UserTable2"
}
}
}
}
Upvotes: 3