从客户端调用API时出现错误代码500

时间:2019-04-07 20:45:38

标签: amazon-web-services

我有一个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"

1 个答案:

答案 0 :(得分:0)

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

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

让我知道它是否仍然无法正常工作。