Протестируйте лямбда-выражение AWS локально с помощью образа контейнера Docker

Мне было трудно заставить эту вещь работать правильно, я пытаюсь вызвать Lambda локально, которая работает в контейнере докеров, но у меня есть следующая проблема

Файл Docker

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


COPY myfunction.py ./

CMD ["myfunction.lambda_handler"]

Файл Python myfunction.py

      import json
import sys

def lambda_handler(event, context):
    print("Hello AWS!")
    print("event = {}".format(event))
    return {
        'statusCode': 200,
    }

Шаг 1:

      docker build --tag custom .

выход

      C:\Users\s.shah\IdeaProjects\YoutubeVideos\Learn>docker build --tag custom .
[+] Building 0.5s (7/7) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                                                                                                                                                                                                                            0.0s
 => => transferring dockerfile: 31B                                                                                                                                                                                                                                                                                                                             0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                                                                                                                                               0.0s
 => => transferring context: 2B                                                                                                                                                                                                                                                                                                                                 0.0s
 => [internal] load metadata for public.ecr.aws/lambda/python:3.8                                                                                                                                                                                                                                                                                               0.5s
 => [internal] load build context                                                                                                                                                                                                                                                                                                                               0.0s
 => => transferring context: 35B                                                                                                                                                                                                                                                                                                                                0.0s
 => [1/2] FROM public.ecr.aws/lambda/python:3.8@sha256:d5a4b8f3f7394358bfe2cb51677f3d14af59c08adf831332cb4501f56dfd64cc                                                                                                                                                                                                                                         0.0s
 => CACHED [2/2] COPY myfunction.py ./                                                                                                                                                                                                                                                                                                                          0.0s
 => exporting to image                                                                                                                                                                                                                                                                                                                                          0.0s
 => => exporting layers                                                                                                                                                                                                                                                                                                                                         0.0s
 => => writing image sha256:6a339ad8416cd93632ae4418e89409dae2e8a684de7990746b613b223a974899                                                                                                                                                                                                                                                                    0.0s
 => => naming to docker.io/library/custom    

Шаг 2:

      docker run -p 9000:8080 random-letter:latest

выход

      INFO[0000] exec '/var/runtime/bootstrap' (cwd=/var/task, handler=)

Шаг 3:

      curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}'

      {"errorMessage": "Unable to unmarshal input: Expecting value: line 1 column 1 (char 0)", "errorType": "Runtime.UnmarshalError", "stackTrace": []}

      INFO[0057] extensionsDisabledByLayer(/opt/disable-extensions-jwigqn8j) -> stat /opt/disable-extensions-jwigqn8j: no such file or directory
WARN[0057] Cannot list external agents                   error="open /opt/extensions: no such file or directory"
START RequestId: d49a7179-7ec5-4122-933f-be04abfed953 Version: $LATEST
Traceback (most recent call last):able to unmarshal input: Expecting value: line 1 column 1 (char 0)
END RequestId: d49a7179-7ec5-4122-933f-be04abfed953
REPORT RequestId: d49a7179-7ec5-4122-933f-be04abfed953  Init Duration: 0.23 ms  Duration: 65.39 ms      Billed Duration: 100 ms Memory Size: 3008 MB    Max Memory Used: 3008 MB

Любая помощь была бы замечательной

2 ответа

Отвечать

https://github.com/lambci/docker-lambda/issues/208 curl -XPOST "http: // localhost: 9000 / 2015-03-31 / functions / function / invocations" -d "{" "" msg " "":"""Привет"""}"

это работает

Для тех, кто использует Postman для вызова конечной точки, вы можете попробовать следующее:

Другие вопросы по тегам