AWS: I want to spin the Lambda function locally written in python.

Asked 2 years ago, Updated 2 years ago, 145 views

Hello.

The development environment is as follows.

It happened when I tried to repair a function that had already been developed. The developer who wrote this function code was a Mac user ㅠ<

Of course, if you run the file locally with py filename.py and let the function run without any parameters, it will return.

To use the parameter event that configures aws lambda, simply local python file drives are not enough, so the package found is python-lambda-local. I wrote the event.json file as instructed in the package and entered the command on the console.

python-lambda-local -l ./ -f handler -t 5 filename.py event.json

However, the expected result from the manual is

[root - INFO - 2018-11-20 17:10:53,352] Event: {'answer': 42}
[root - INFO - 2018-11-20 17:10:53,352] START RequestId: 3c8e6db4-886a-43da-a1c7-5e6f715de531 

(...)

[root - INFO - 2018-11-20 17:10:53,359] END RequestId: 3c8e6db4-886a-43da-a1c7-5e6f715de531
[root - INFO - 2018-11-20 17:10:53,360] REPORT RequestId: 3c8e6db4-886a-43da-a1c7-5e6f715de531  Duration: 2.17 ms
[root - INFO - 2018-11-20 17:10:53,360] RESULT:

In contrast, the following message was taken.

[root - INFO - 2019-10-22 12:18:03,798] Event: {'queryStringsParameters': {'datasetId': '6a9d03d7-5204-41b0-9e34-03c45b1224d7'}}
[root - INFO - 2019-10-22 12:18:03,798] START RequestId: 1134c088-32c4-495e-9ed2-b3580451a8d7 Version: 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "c:\users\administrator\appdata\local\programs\python\python38\lib\multiprocessing\spawn.py", line 116, in 
spawn_main
    exitcode = _main(fd, parent_sentinel)
  File "c:\users\administrator\appdata\local\programs\python\python38\lib\multiprocessing\spawn.py", line 126, in 
_main
    self = reduction.pickle.load(from_parent)
ModuleNotFoundError: No module named 'request-1134c088-32c4-495e-9ed2-b3580451a8d7'

So I looked up in this package, and unfortunately, there must be no way to turn it in the window. If anyone knows how to turn the lambda function written in python in Windows, please reply.

Thank you.

python lambda aws local

2022-09-22 15:48

1 Answers

Lambda is not unusual.

def lambda_handler(event, context):

The function that looks like this (name depends) is executed instead.

Eventually, you just need to know what event, context is.

Event is dict and context can be found in the link below.

https://docs.aws.amazon.com/en_pv/lambda/latest/dg/python-context-object.html

In other words, running lambda locally means that you can run the function with the above parameter values.

Usually, when using Lambda, rather than implementing logic in the handler, do deregistration to prevent coupling by implementing it in other functions.

Of course, if you need to call another aws service in Lambda, you may need to run it locally.

SAM allows you to use docker to build an environment such as debugging on your local PC.

https://docs.aws.amazon.com/en_pv/serverless-application-model/latest/developerguide/what-is-sam.html


2022-09-22 15:48

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.