使用 Lambda 的 Axios 删除方法

Axios delete method with Lambda

我有以下代码从我的 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 函数 table:

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);
});

问题是,该项目不会从 table 中删除,原因是 Lambda 没有收到来自 ReactApp 的“contactId”,其中包含应删除的 ID。因为当我像下面这样测试来自 Lambda 的代码时,它有效:

  Key: {
    id: "123" //Actual ID in table
  },

所以我认为问题在于反应:

key1: `${contactId}`

我错过了什么?

DELETE 请求没有正文。

使用

await axios.delete('https://api.com/prod', { 
  data: {key1: `${contactId}`}
 });