簡體   English   中英

NextJS API Lambda AWS Amplify 執行錯誤

[英]NextJS API Lambda Execution Error AWS Amplify

我有一個在 AWS amplify 上運行的 NextJS 應用程序。 我通過向我的項目添加pages/api目錄構建了一個基本的 REST API。 端點返回 200 和一些測試 JSON 數據。 當我在本地運行項目時,這很好用。 I deployed to AWS Amplify and the build detects that a Next API is present so it provisions a Lambda and configures the CloudFront behavior for /api/* routes to point to the Lambda function. 當點擊 API CloudFront 返回 503 錯誤:

503 ERROR
The request could not be satisfied.
The Lambda function associated with the CloudFront distribution is invalid or doesn't have the required permissions. We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner.
If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.
Generated by cloudfront (CloudFront)
Request ID: YnQI9alkoBXwkmkkpXwa29zqXaOT06VCXiBZWJI6xQVkhQ8MElB2bQ==

CloudFront 似乎沒有調用 Lambda,因為我在 Cloudwatch 中看不到任何日志。 我嘗試調試並構建了一個測試,將模擬 CloudFront 事件請求傳遞給 Lambda,但我無法讓我的 API 成功執行。

似乎 Amplify/Next 提供了很多樣板代碼來支持 Next API 路由,所以我不確定將調試工作集中在哪里。

有沒有人遇到過這個問題? 任何指導或建議都會非常有幫助!

我確實遇到了類似的問題,但我正在使用帶有@sls-next/serverless-component組件的無服務器。 因為目前還不支持 NextJs 12 版本。

在我的 package.json 中,我最近在 11 中強制使用 NextJs 版本,這種情況是 11.1.4。

// package.json
 {
  "name": "next-aws",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start"
  },
  "dependencies": {
    "next": "^11.1.4",
    "react": "17.0.2",
    "react-dom": "17.0.2"
  },
  "devDependencies": {
    "@types/node": "^14.14.37",
    "@types/react": "^17.0.3",
    "typescript": "^4.2.3"
  }
}

希望您現在能夠解決您的問題。

我在將 API 路由部署到 Amplify 時也遇到了一些問題,但我發現這個 FAQ 頁面為我提供了解決方案(缺少環境變量)。 該頁面還列出了如何查找函數的日志。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM