Naxi
Naxi

Reputation: 2026

Unable to import module 'app': No module named 'app' in Aws Lambda using Chalice

I am having below lambda function which uses Chalice.

from chalice import Chalice
from chalicelib import lookup_helper
import os 

try:
    from urllib import unquote
except ImportError:
    from urllib.parse import unquote

app = Chalice(app_name='some_app')
@app.route('/some_route', methods=['GET'])
def some_func(arg):
    //some code

When I test this function I get below error

{"errorMessage": "Unable to import module 'app': No module named 'app'", "errorType": "Runtime.ImportModuleError"}
Tue Sep 22 11:59:10 UTC 2020 : Lambda execution failed with status 200 due to customer function error: Unable to import module 'app': No module named 'app'.

Can anyone please help me out here. Python - 3.7

Update--

from chalice import Chalice
import os 

app = Chalice(app_name='some_app')
@app.route('/some_route', methods=['GET'])
def some_func(arg):
    return {}

Reduced the function to above. Still same error.

When I checked the pipeline (azure devops), I see below error in the logs, though the step passes as a whole.

FileExistsError: [Errno 17] File exists: 'build/lambda/requests'

requirement.txt

requests==2.22.0

Upvotes: 1

Views: 5506

Answers (1)

balderman
balderman

Reputation: 23815

see https://chalice-workshop.readthedocs.io/en/latest/media-query/00-intro-chalice.html

Add a new function hello_world decorated by app.lambda_function() that returns {"hello": "world"}. Your app.py file should now consist of the following lines:

from chalice import Chalice

app = Chalice(app_name='workshop-intro')

@app.lambda_function()
def hello_world(event, context):
    return {'hello': 'world'}

What is the name of you python file. Is it 'app.py' ?

Upvotes: 1

Related Questions