Search code examples
amazon-web-servicesamazon-dynamodbnosql

AWS Update table not working


I'm uisng updateTable of DynmaoDB and I'm passing the following params object:

{
    "TableName": "movies",
    "AttributeDefinitions": [{
            "AttributeName": "subtitle",
            "AttributeType": "S"
        }],
    "GlobalSecondaryIndexUpdates": [{
            "Create": {
                "IndexName": "subtitle",
                "ProvisionedThroughput": {
                    "ReadCapacityUnits": "5",
                    "WriteCapacityUnits": "5"
                },
                "KeySchema": [{
                        "AttributeName": "subtitle",
                        "KeyType": "HASH"
                    }],
                "Projection": {
                    "ProjectionType": "ALL"
                }
            }
        }],
    "ProvisionedThroughput": {
        "ReadCapacityUnits": "5",
        "WriteCapacityUnits": "5"
    }
}

but it gives me the following error:

  • UnexpectedParameter: Unexpected key 'AttributeDefinitions' found in params
  • UnexpectedParameter: Unexpected key 'Create' found in params.GlobalSecondaryIndexUpdates[0]]

But based on the the documentation I need to pass them?! So why is it giving me this error?

UPDATED:

Thanks to Daniela Miao's suggestion my problem is fixed by changing the SDK version; but I have run into another issue; again based on the documentation, if we want to create multiple GSIs we need to have multiple objects in "GlobalSecondaryIndexUpdates" field, so I'm passing the following params, but it does not update the GSIs; however if I'm just creating one GSI (passing one object in "GlobalSecondaryIndexUpdates" field, it works); here is the params I'm passing for creating multiple GSIs:

{
    "TableName": "movies",
    "AttributeDefinitions": [{
            "AttributeName": "id",
            "AttributeType": "N"
        }, {
            "AttributeName": "title",
            "AttributeType": "S"
        }, {
            "AttributeName": "subtitle",
            "AttributeType": "S"
        }],
    "GlobalSecondaryIndexUpdates": [{
            "Create": {
                "IndexName": "title",
                "ProvisionedThroughput": {
                    "ReadCapacityUnits": "5",
                    "WriteCapacityUnits": "5"
                },
                "KeySchema": [{
                        "AttributeName": "title",
                        "KeyType": "HASH"
                    }],
                "Projection": {
                    "ProjectionType": "ALL"
                }
            }
        }, {
            "Create": {
                "IndexName": "subtitle",
                "ProvisionedThroughput": {
                    "ReadCapacityUnits": "5",
                    "WriteCapacityUnits": "5"
                },
                "KeySchema": [{
                        "AttributeName": "subtitle",
                        "KeyType": "HASH"
                    }],
                "Projection": {
                    "ProjectionType": "ALL"
                }
            }
        }]
}

Am I passing the params in a wrong format?

Thanks :-)


Solution

  • Which SDK version are you using? I believe adding an index to an existing table is a new capability that was recently released, so it should be supported only in the newest SDK version 2.1.8: http://aws.amazon.com/releasenotes/SDK/JavaScript/3682546508553819