shelum
shelum

Reputation: 163

Delete/Update DynamoDB entries with AWS API

I am trying to figure out how to make an API to allow for updating/deleting entries with the AWS API. Ideally. I want it so that when you call'apijfkdlsfjdlaf.com.aws/delete/{idnumber}' It will delete that particular entry.

My integration requests calls DeleteItem from DynamoDB and looks like:

{
"TableName": "Blah",
"KeyConditionExpression": "blahID= :v1",
"ExpressionAttributeValues": {
    ":v1": {
        "S": "$input.params('blahID')"
    }
}
}

I am able to read/write entries, so I know my access control is setup appropriately, but when I test the delete command I receive the follwing:

{
  "__type": "com.amazon.coral.validate#ValidationException",
  "message": "1 validation error detected: Value null at 'key' failed to satisfy constraint: Member must not be null"
}

And the logs: http://pastebin.com/M4sSGWUS

Any help is appreciated.

Edit: I've changed the integration request to align with the documentation on their website:

var AWS = require("aws-sdk");
var docClient = new AWS.DynamoDB.DocumentClient();

var table = "Blah";
var ID= "$input.params('blahID')";

var params = {
TableName:table,
Key:{
    "blahID":ID,
}
};

docClient.delete(params, function(err, data) {
   if (err) {
       console.error("Unable to delete item. Error JSON:",    JSON.stringify(err, null, 2));
   } else {
       console.log("DeleteItem succeeded:", JSON.stringify(data, null, 2));
   }
});

Now getting a "__type": "com.amazon.coral.service#SerializationException" error

Upvotes: 1

Views: 6919

Answers (1)

shelum
shelum

Reputation: 163

Changed the integration request to:

{ 
"TableName": "Blah",
"Key": {
    "blahID": {
        "S": "$input.path('$.blahID')"
        }
    }
}

Seems to work now.

Upvotes: 1

Related Questions