I have an AWS Lambda function behind API Gateway v2 that should delete an item from DynamoDB. When creating the endpoint, I based it off the AWS example code Delete an item from a table.
The parameter substitution works for other statements, such as SELECT
and UPDATE
, but the DELETE
fails to execute due to the deserializer middleware failing to format the command.
Here's my PartiQL delete statement:
// Create PartiQL search query to delete item
const params = {
Statement: `DELETE FROM "${tableName}" WHERE eventId=? AND siteId=?`,
Parameters: [{S: eventId}, {S: siteId}],
};
// Delete item from database
await ddbDocClient.send(new ExecuteStatementCommand(params));
I receive the following error:
ERROR SerializationException: Start of structure or map found where not expected
at throwDefaultError (/var/task/node_modules/@aws-sdk/smithy-client/dist-cjs/default-error-handler.js:8:22)
at de_ExecuteStatementCommandError (/var/task/node_modules/@aws-sdk/client-dynamodb/dist-cjs/protocols/Aws_json1_0.js:1593:51)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async /var/task/node_modules/@aws-sdk/middleware-serde/dist-cjs/deserializerMiddleware.js:7:24
at async /var/task/node_modules/@aws-sdk/lib-dynamodb/dist-cjs/baseCommand/DynamoDBDocumentClientCommand.js:26:34
at async /var/task/node_modules/@aws-sdk/middleware-signing/dist-cjs/middleware.js:14:20
at async /var/task/node_modules/@aws-sdk/middleware-retry/dist-cjs/retryMiddleware.js:27:46
at async /var/task/node_modules/@aws-sdk/middleware-logger/dist-cjs/loggerMiddleware.js:7:26
at async Runtime.handler (/var/task/src/events/endpoints/delete.js:24:9)
Here are the inputs I'm using:
{
"Statement": "DELETE FROM \"myTable\" WHERE eventId=? AND siteId=?",
"Parameters": [
{
"S": "d7b7f7fb-78c5-4d76-8b47-1316ae412de4"
},
{
"S": "'test_site_1"
}
]
}
However, if I provide only a statement with manual values fed in, it works:
DELETE FROM "myTable" WHERE eventId = '828474d8-982f-4955-8aed-bb8a8f373e4c' AND siteId = 'test_site_1'
I'm guessing that this may be an issue with the SDK's serialization middleware? Any ideas on how to resolve this?
I was using the wrong import
import {ExecuteStatementCommand} from '@aws-sdk/lib-dynamodb';
Instead of
import {ExecuteStatementCommand} from '@aws-sdk/client-dynamodb';