I have a DynamoDB table with the following attributes:
SubscriptionsTable:
Type: AWS::DynamoDB::Table
DeletionPolicy: Retain
Properties:
TableName: ${self:custom.subscriptionsTableName}
AttributeDefinitions:
- AttributeName: eventName
AttributeType: S
- AttributeName: hookUrl
AttributeType: S
KeySchema:
- AttributeName: eventName
KeyType: HASH
- AttributeName: hookUrl
KeyType: RANGE
I would like to delete an item according to its hookUrl and eventName. That's the code of my repository:
const deleteSubscriptionFromRepository = async ({
hookUrl,
eventName,
}: {
hookUrl: string;
eventName: SubscriptionEventName;
}) => {
const mapper = getDatabaseMapper();
try {
return await mapper.delete(Object.assign(new SubscriptionModel(), { hookUrl, eventName }));
} catch (e) {
throw new DatabaseAccessError(e.message, 'deleteSubscriptionFromRepository');
}
};
Instead of using directly the DynamoDB client, I'm using the DataMapper from '@aws/dynamodb-data-mapper';
But I'm receiving the following error:
DatabaseAccessError: The number of conditions on the keys is invalid
How is that possible to delete an item according to its partition and range key? What I'm doing wrong in the above code?