如何在无服务器离线状态下运行 Lambda Docker

Vin*_*ius 6 serverless-framework serverless-offline

我想serverless offline使用指向 Docker 映像的 Lambda 函数来运行。

当我尝试运行时serverless offline,我只是收到:

Offline [http for lambda] listening on http://localhost:3002
Function names exposed for local invocation by aws-sdk:
           * hello-function: sample-app3-dev-hello-function
Run Code Online (Sandbox Code Playgroud)

如果我尝试访问http://localhost:3002/hello,会返回404错误


serverless.yml

Offline [http for lambda] listening on http://localhost:3002
Function names exposed for local invocation by aws-sdk:
           * hello-function: sample-app3-dev-hello-function
Run Code Online (Sandbox Code Playgroud)

app/myfunction.py

service: sample-app3
frameworkVersion: '3'

plugins:
  - serverless-offline

provider:
  name: aws
  ecr:
    images:
      sampleapp3image:
        path: ./app/
        platform: linux/amd64

functions:
  hello-function:
    image:
      name: sampleapp3image
    events:
      - httpApi:
          path: /hello
          method: GET
Run Code Online (Sandbox Code Playgroud)

app/Dockerfile

FROM public.ecr.aws/lambda/python:3.9

COPY myfunction.py ./

CMD ["myfunction.lambda_handler"]
Run Code Online (Sandbox Code Playgroud)

Pro*_*1ve 2

目前serverless-offline插件不支持此类功能。有一个问题悬而未决,讨论是围绕支持此用例开始的:https://github.com/dherault/serverless-offline/issues/1324