Edit 2: The main reason was that I had several DOCKER environment variables that called my function calls to redirect to the remote Docker host, and not for SAM Local. As soon as I turned them off, the functions started to work.
Edit: I cloned docker-lambda and tried to run one of my examples and get the same error.
docker run
START RequestId: 73a433fc-1d8a-4cdb-a66d-61bd667e13ba Version: $LATEST
Unable to import module 'lambda_function': No module named 'lambda_function'
END RequestId: 73a433fc-1d8a-4cdb-a66d-61bd667e13ba
REPORT RequestId: 73a433fc-1d8a-4cdb-a66d-61bd667e13ba Duration: 1 ms Billed Duration: 100 ms Memory Size: 1536 MB Max Memory Used: 15 MB
{"errorMessage": "Unable to import module 'lambda_function'"}
I am trying to configure SAM Local using the Python lambda function and continue to give up on the import error of the module in the header.
My template.yaml looks like this:
AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
ProposalsTable:
Type: "AWS::Serverless::SimpleTable"
AddProposal:
Type: "AWS::Serverless::Function"
Properties:
Handler: lambda_function.lambda_handler
Runtime: python3.6
Policies: AmazonDynamoDBFullAccess
Environment:
Variables:
TABLE_NAME: !Ref ProposalsTable
Events:
Vote:
Type: Api
Properties:
Path: /proposals
Method: get
I have lambda_function.py in the same folder as template.yaml.
I run: sam local start-api
and it starts normally:
Mounting lambda_function.lambda_handler (python3.6) at http://127.0.0.1:3000/proposals [GET]
Then I do:
curl http://127.0.0.1:3000/proposals
"" :
Unable to import module 'lambda_function': No module named 'lambda_function'
Function returned an invalid response (must include one of: body, headers or statusCode in the response object): %!s(<nil>)
(, init.py)
googled , AWS Lambda; SAM Local.
, - . node.js . https://github.com/awslabs/aws-sam-local/tree/develop/samples/hello-world/node
2018/01/04 15:20:41 Invoking index.handler (nodejs6.10)
2018/01/04 15:20:41 Mounting /Users/me/code/sam-local-prototype as /var/task:ro inside runtime container
2018/01/04 15:20:46 Function index.handler timed out after 3 seconds
?