Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nodejs DynamoDB CreateTable hash only with no range returns ValidationException

I am trying to create a table on dynamodb trough their aws-sdk on nodejs. Below is the parameter I am passing on dynamodb.createTable:

{
    TableName: 'new_table',
    ProvisionedThroughput: {
        ReadCapacityUnits: 1,
        WriteCapacityUnits: 1
    },
    KeySchema: [
        {AttributeName: 'primary_key', KeyType: 'HASH'}
    ],
    AttributeDefinitions: [
        {AttributeName: 'primary_key', AttributeType: 'S'},
        {AttributeName: 'some_attribute', AttributeType: 'S'}
    ]
}

This returns

ValidationException: One or more parameter values were invalid: Number of attributes in KeySchema does not exactly match number of attributes defined in AttributeDefinitions

I have fixed this by adding 'some_attribute' on 'KeySchema' but what I want is a 'hash' only table with no 'range'.

like image 490
Gene Diaz Avatar asked Sep 06 '14 09:09

Gene Diaz


1 Answers

Solved: When creating a table, you only need to specify the KeySchema attributes and not all attributes that you will be putting on the table. So in my case I just need to specify the 'primary_key'

{
    TableName: 'new_table',
    ProvisionedThroughput: {
        ReadCapacityUnits: 1,
        WriteCapacityUnits: 1
    },
    KeySchema: [
        {AttributeName: 'primary_key', KeyType: 'HASH'}
    ],
    AttributeDefinitions: [
        {AttributeName: 'primary_key', AttributeType: 'S'},
    ]
}
like image 141
Gene Diaz Avatar answered Oct 12 '22 11:10

Gene Diaz