簡體   English   中英

AWS Lambda 使用圖像容器找不到處理程序導出

[英]AWS Lambda using Image Container cannot find handler export

使用無服務器 AWS Lambda 圖像容器,但找不到處理程序。

無服務器迫使我:

  • 使用圖像時使用命令
  • 在我的命令中使用我的處理程序的相對路徑

無服務器.yml (v3.25.0)

service: example-service
 
provider:
  name: aws
  ecr:
    images:
      appimage:
        path: ./
        file: Dockerfile
        platform: linux/arm64
 
functions:
  getDocument:
    image:
      command:
        - src/function/getDocument/index.handler
      entryPoint:
        - '/lambda-entrypoint.sh'
      name: appimage

Dockerfile

FROM public.ecr.aws/lambda/nodejs:12
 
COPY src/function/getDocument/index.ts ./

CMD ["index.handler"]

錯誤

"errorType":"Runtime.HandlerNotFound",
"errorMessage":"src/function/getDocument/index.handler is undefined or not exported",
"stack":["Runtime.HandlerNotFound: index.handler is undefined or not exported", "at Object.module.exports.load (/var/runtime/UserFunction.js:144:11)"

我不確定 UserFunction.js 是如何適應這個的。

這是我使用 webpack 的獨特設置的解決方案。

我需要

  1. 構建 getDocument function(無服務器包)
  2. 將構建文件復制到我的容器中(Dockerfile)
  3. 將 function 部署到 aws(無服務器部署)
  4. 通過 aws 管理控制台(網站)將我的命令從“src/function/getDocument/index.handler”更改為“index.handler”

無服務器.yml

service: example-service
 
provider:
  name: aws
  ecr:
    images:
      appimage:
        path: ./
        file: Dockerfile
        platform: linux/arm64
 
functions:
  getDocument:
    image:
      command:
        - src/function/getDocument/index.handler
      entryPoint:
        - '/lambda-entrypoint.sh'
      name: appimage

Dockerfile

FROM public.ecr.aws/lambda/nodejs:14

RUN yum -y upgrade
RUN yum -y install YOUR_PACKAGES
 
COPY build/getDocument/index.js build/getDocument/index.js.map ${LAMBDA_TASK_ROOT}

RUN npm add text2png

CMD ["index.handler"]

暫無
暫無

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

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