1

this is my lambda function

var AWS = require("aws-sdk");
var dynamodb = new AWS.DynamoDB();
var docClient = new AWS.DynamoDB.DocumentClient();
exports.handler = (event, context, callback) => {

var params = {
    TableName: 'xx',
    Key: {
        project_id : event.id,
        name: event.name
    }
};

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

my test event is

{
"id": "1490022172442",
"name":"xcv"
}

And still i got error "The provided key element does not match the schema". POST and GET is working nice but I am stucked here.

2
  • 1
    Does your table has project_id defined as hash key and name as sort key? what do you mean by GET and POST are working fine? Do you mean create item and get item are working fine? Commented Mar 21, 2017 at 22:53
  • That was the reason, I missed sort key! Commented Mar 22, 2017 at 0:00

2 Answers 2

1

In order to delete an item from DynamoDB table, you have to provide both partition and sort key in key attributes. It should work if you include sort key on key attributes.

Sign up to request clarification or add additional context in comments.

1 Comment

Is there any other way to getItem using only index key ?
0

Below given is a code snippet for deleting an item where there is only primary key and no sort key is provided

ar AWS = require("aws-sdk");
var dynamodb = new AWS.DynamoDB();
var docClient = new AWS.DynamoDB.DocumentClient();
exports.handler = (event, context) => {
console.log('event= ' + JSON.stringify(event));
console.log('context= ' + JSON.stringify(context));

var params = {
TableName: 'TableName',
Key: {
    kundeId : event.kundeId,
    name: event.name
}
};

docClient.delete(params, function(err, data) {
if (err) {
    console.error("Unable to read item. Error JSON:", JSON.stringify(err, null, 2));
} else {
     console.log("DEBUG:  deleteItem worked. ");
    context.succeed(data);

 }}
 );
 };

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.