0
votes

I am trying to do a batch delete following this documentation. It gives the following example:

var params = {
  RequestItems: { /* required */
    '<TableName>': [
      {
        DeleteRequest: {
          Key: { /* required */
            '<AttributeName>': someValue /* "str" | 10 | true | false | null | [1, "a"] | {a: "b"} */,
            /* '<AttributeName>': ... */
          }
        },
        PutRequest: {
          Item: { /* required */
            '<AttributeName>': someValue /* "str" | 10 | true | false | null | [1, "a"] | {a: "b"} */,
            /* '<AttributeName>': ... */
          }
        }
      },
      /* more items */
    ],
    /* '<TableName>': ... */
  },
  ReturnConsumedCapacity: INDEXES | TOTAL | NONE,
  ReturnItemCollectionMetrics: SIZE | NONE
};
documentclient.batchWrite(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);           // successful response
});
  • Key — required — (map) — a serializable JavaScript object. For information about the supported types see the DynamoDB Data Model

Looking further into the DynamoDB documentation I find this parameter description

  • Key - A map of primary key attribute values that uniquely identify the item. Each entry in this map consists of an attribute name and an attribute value. For each primary key, you must provide all of the key attributes. For example, with a simple primary key, you only need to provide a value for the partition key. For a composite primary key, you must provide values for both the partition key and the sort key.

My table uses both partition and sort keys so I must use a composite key. I can't really find an example of how this request looks, I have tried to follow the example in the documentation above but it neither throws an error or deletes the required items.

I have tried with the following parameters as in the first example:

const params = {
    "RequestItems": {
        "table-name": [
            {
                "DeleteRequest": {
                    "Key": {
                        "partition-key-col-name": "partitionKeyValue",
                        "sort-key-col-name": "sortKeyValue"
                    }
                }
            },
            {
                "DeleteRequest": {
                    "Key": {
                        "partition-key-col-name": "partitionKeyValue",
                        "sort-key-col-name": "sortKeyValue"
                    }
                }
            }
        ]
    }
}

A second attempt following the parameter formatting from the second example:

const params = {
    "RequestItems": {
        "table-name": [
            {
                "DeleteRequest": {
                    "Key": {
                        "partition-key-col-name": {
                            "S": "partitionKeyValue"
                        },
                        "sort-key-col-name": {
                            "S": "sortKeyValue"
                        }
                    }
                }
            },
            {
                "DeleteRequest": {
                    "Key": {
                        "partition-key-col-name": {
                            "S": "partitionKeyValue"
                        },
                        "sort-key-col-name": {
                            "S": "sortKeyValue"
                        }
                    }
                }
            }
        ]
    }
}

I just get back 'UnprocessedItems'

{ UnprocessedItems: {} }

Where am I going wrong?

1
I believe you would use the first method with documentclient. Are you saying nothing is getting logged? Neither of your console.log statements are happening? I see you tagged this with aws-lambda, so is there a timeout message or something in the Lambda log? Is the Lambda function configured to run in a VPC?Mark B
Thanks Mark. I get back { UnprocessedItems: {} } from documentclient.batchWritenewprogrammer
If you're getting { UnprocessedItems: {} }, Then it's mean your code is working fine Because right now i did POC for you and it's runs perfectly.Abdul Moeez
@AbdulMoeez You're correct, the code was working perfectly! Something else was throwing me off. Thanks.newprogrammer

1 Answers

0
votes

Parameters from the first example did in fact work, something else in the code was throwing me off.