【发布时间】:2022-01-04 05:50:46
【问题描述】:
我有以下代码从我的contactApp中删除一个联系人,它在React中使用axios来发送请求:
export const removeContact = createAsyncThunk(
'contactsApp/contacts/removeContact',
async (contactId, { dispatch, getState }) => {
await axios.delete('https://api.com/prod', {
key1: `${contactId}`
});
console.log(">>>>>>>" + contactId)
return contactId;
}
);
这是从 DynamoDB 表中删除项目的 Lambda 函数:
var params = {
TableName : 'Contacts',
Key: {
id: event.key1
},
};
var documentClient = new AWS.DynamoDB.DocumentClient({region: "us-west-2"});
documentClient.delete(params, function(err, data) {
if (err) console.log(err);
else console.log(data);
});
问题是,该项目不会从表中删除,原因是 Lambda 没有收到来自 ReactApp 的“contactId”,其中包含应该删除的 id。因为当我像下面这样测试来自 Lambda 的代码时,它可以工作:
Key: {
id: "123" //Actual ID in table
},
所以我认为问题在于反应:
key1: `${contactId}`
我错过了什么?
【问题讨论】:
标签: javascript node.js reactjs lambda axios