You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Amplify API删除请求报错:端点未识别(404)

问题:AWS Amplify API DELETE请求404错误,GET/POST请求正常

在使用aws-amplify/api库时,POST、GET请求均正常(包括按CustomerId查询单条客户信息的GET接口),但同一端点发起DELETE请求时返回404错误。已参考AWS官方del方法文档编写代码,本地AWS账号权限已最大化,排查过GraphQL或资源删除相关问题,无法解决,请求协助排查。

正常的GetOneCustomer代码

async function getOneCompany() {
  try {
    const restOperation = del({
      apiName: GladwyneAPIName,
      path: `${GladwynePath}/1`,
    });
    console.log("Get One Worked");
    const { body } = await restOperation.response;
    const response = await body.json();
    console.log("Response Recieved: ", response);
    return response;
  } catch (error) {
    console.log("Get Call Failed: ");
    console.log(error.response.body);
  }
}

报错的Delete One Customer代码

async function deleteOneCustomer(customer) {
  try {
    const returnedStatusCode = del({
      apiName: GladwyneAPIName,
      path: `/Gladwyne/Customer/${customer.CustomerId}`,
      options: {
        queryParams: {
          CustomerId: customer.CustomerId,
        },
      },
    });
    const { body } = await returnedStatusCode.response;
    const returnedResult = await body.json();
    console.log("Returned Result: ", returnedResult);
    return returnedResult;
  } catch (error) {
    if (error instanceof ApiError) {
      if (error.response) {
        const { statusCode, headers, body } = error.response;
        console.error(
          `Received ${statusCode} error response with payload: ${body}`
        );
      }
    }
    console.log("Plain old error message: ", error);
    logger.error("Error from class: ", error);
  }
}

错误信息

  • 未知错误:未知错误
  • DELETE 请求地址:https://{ID}.execute-api.us-east-1.amazonaws.com/gladwyne/Gladwyne/Customer/3?CustomerId=3 返回404(未找到)
  • 高级日志内容:无法 DELETE /Gladwyne/Customer/3

排查建议

  • 检查路径重复问题:从错误URL可见,路径出现重复的/Gladwyne(域名后是/gladwyne,代码中path又添加了/Gladwyne)。对比正常GET请求使用${GladwynePath}/1,需确认GladwynePath的取值是否已包含/Gladwyne/Customer,若已包含,DELETE的path拼接后会导致路径重复,与API Gateway部署的实际路径不匹配,引发404。
  • 验证API Gateway配置:确认API Gateway中该资源是否配置了DELETE方法,且路径大小写、层级与请求完全一致(注意gladwyne和Gladwyne的大小写差异)。
  • 移除冗余的queryParams:DELETE请求已通过路径传递CustomerId,无需在queryParams中重复传递,冗余参数可能导致路径解析异常,建议删除options中的queryParams配置。
  • 修正代码笔误:正常GET函数中错误使用了del方法(应为get),虽实际请求正常,但需确认此处变量或方法名是否存在混淆,避免影响后续排查。

内容的提问来源于stack exchange,提问作者Stephen Smith

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 08:37:46