首页 > 解决方案 > 从客户端调用 API 时出现错误代码 500

问题描述

我有一个 Lambda 函数,当我从我的 React 应用程序调用它时,我收到以下 2 个错误:

POST https://x7429ccke5.execute-api.eu-west-1.amazonaws.com/prod/sites 500

Uncaught (in promise) Error: Request failed with status code 500 at createError (createError.js:17) at settle (settle.js:19) at XMLHttpRequest.handleLoad (xhr.js:78)

我的网站上还没有登录系统,所以我想在不需要许可的情况下调用 api,所以在我的 serverless.yml 上,我把它作为

functions:
  # Defines an HTTP API endpoint that calls the main function in create.js
  # - path: url path is /notes
  # - method: POST request
  # - cors: enabled CORS (Cross-Origin Resource Sharing) for browser cross
  #     domain api call
  # - authorizer: authenticate using the AWS IAM role
  createSite:
    handler: CreateSite.main
    events:
      - http:
          path: sites
          method: post
          cors: true
          arn: "arn:aws:execute-api:eu-west-1:106845550704:x7429ccke5/*/POST/sites"

标签: amazon-web-services

解决方案


我怀疑问题出在 API Gateway 与 lambda 的集成上。引发 500 错误的是您的 API 网关。请检查您的 API 网关是否已暂存。如果它已上演,请检查以下内容:

https://docs.aws.amazon.com/apigateway/latest/developerguide/amazon-api-gateway-using-stage-variables.html#call-api-http-backend-via-stage-variable

让我知道它是否仍然不起作用。


推荐阅读