是的,您可以使用AWS SDK来使用GSI删除DynamoDB中的项目。下面是一个使用Node.js SDK的示例,它首先创建一个DynamoDB客户端,然后使用GSI来删除项目:
const AWS = require('aws-sdk');
const docClient = new AWS.DynamoDB.DocumentClient();
const params = {
TableName: 'Your_Table_Name',
IndexName: 'Your_GSI_Name',
Key: {
'GSI_Partition_Key': 'Your_Partition_Key_Value',
'GSI_Sort_Key': 'Your_Sort_Key_Value'
},
ReturnValues: 'ALL_OLD'
};
docClient.delete(params, (err, data) => {
if (err) {
console.log('Error:', err);
} else {
console.log('Successfully deleted item:', data);
}
});
请注意,此示例采用了在“Your_Table_Name”和“Your_GSI_Name”上的索引,并使用“Your_Partition_Key_Value”和“Your_Sort_Key_Value”作为GSI的分区键和排序键的值。您需要将它们替换为您自己的值来使代码在您的环境中工作。