I have a partition key and a sort key on table (DynamoDB)
partition key: ClientID sort key: CaseID
The Delete Code (Lambda):
'use strict';
const AWS = require('aws-sdk');
exports.handler = async (event, context) => {
const documentClient = new AWS.DynamoDB.DocumentClient();
let responseBody = "";
let statusCode = 0;
const {ClientID} = event.pathParameters;
const {CaseID} = event.pathParameters;
const params = {
TableName: "Case",
Key: {
ClientID: ClientID,
CaseID: CaseID
}
};
try {
const data = await documentClient.delete(params).promise();
responseBody = JSON.stringify(data.Items.key);
statusCode = 204;
} catch(err) {
responseBody = `Unable to delete Case: ${err}`;
statusCode = 403;
}
const response = {
statusCode: statusCode,
headers: {
"Content-Type": "application/json",
"access-control-allow-origin":"*"
},
body: responseBody
};
return response;
};
If I try to delete element on API Getaway:
I got this error:
Status: 403 Unable to delete Case: ValidationException: The provided key element does not match the schema
How I can fix this error.
On The AWS Lambda with API Gateway:
I get this error:
Response "errorType": "TypeError", "errorMessage": "Cannot destructure property 'ClientID' of 'event.pathParameters' as it is undefined.",
Thank you.