简体   繁体   English

"errorMessage": "无法导入模块 'app': 没有名为 'app' 的模块", "errorType": "Runtime.ImportModuleError",

[英]"errorMessage": "Unable to import module 'app': No module named 'app'", "errorType": "Runtime.ImportModuleError",

I'm getting this error when trying to test my lambda-function尝试测试我的 lambda 函数时出现此错误

  "errorMessage": "Unable to import module 'app': No module named 'app'",
  "errorType": "Runtime.ImportModuleError",
  "stackTrace": []
}

Here's my python code since I'd imagine it's an issue with my code?这是我的 python 代码,因为我认为这是我的代码的问题? I also have my lambda function handler on aws set to app.handler since this file's name is app.py.我还将 aws 上的 lambda function 处理程序设置为 app.handler,因为该文件的名称是 app.py。 Really not sure if it's an issue with my lambda function handler or my code, or both真的不确定这是否是我的 lambda function 处理程序或我的代码或两者的问题

import requests
import os
import smtplib
from datetime import datetime

# https://openweathermap.org/api/one-call-api

# empire state building
lat = '40.75009231913161'
lon = '-73.98638285425646'
exclude = 'minutely,hourly,alerts'

url = (
    'https://api.openweathermap.org/data/2.5/onecall?' +
    'lat={lat}&lon={lon}&exclude={exclude}&appid={API_key}&units=imperial'
)


if os.path.isfile('.env'):
    from dotenv import load_dotenv
    load_dotenv()


def __send_email(msg: str) -> None:
    gmail_user = os.getenv('EMAIL_USER')
    gmail_password = os.getenv('EMAIL_PASSWORD')

    # Create Email
    mail_from = gmail_user
    mail_to = gmail_user
    mail_subject = f'Weather Today {datetime.today().strftime("%m/%d/%Y")}'
    mail_message = f'Subject: {mail_subject}\n\n{msg}'

    # Send Email
    server = smtplib.SMTP('smtp.gmail.com', 587)
    server.starttls()
    server.login(gmail_user, gmail_password)
    server.sendmail(mail_from, mail_to, mail_message)
    server.close()


def handler(event, context):
    response = requests.get(url.format(
        lat=lat,
        lon=lon,
        exclude=exclude,
        API_key=os.getenv('WEATHER_API_KEY')
    ))

    data = response.json()

    rain_conditions = ['rain', 'thunderstorm', 'drizzle']
    snow_conditions = ['snow']

    today_weather = data['daily'][0]['weather'][0]['main'].lower()

    if today_weather in rain_conditions:
        msg = 'Pack an umbrella!'
    elif today_weather in snow_conditions:
        msg = 'Pack your snow boots!'
    else:
        msg = 'Clear skies today!'

    __send_email(msg)

handler(None, None)

My ZIP is located in an S3 bucket in python/project.zip and the structure of my zip folder is python/app.py + requirements.txt我的 ZIP 位于 python/project.zip 的 S3 存储桶中,我的 zip 文件夹的结构是 python/app.py + requirements.txt

the structure of my zip folder is python/app.py + requirements.txt我的 zip 文件夹的结构是 python/app.py + requirements.txt

It should be only app.py , not python/app.py .它应该只是app.py ,而不是python/app.py Also there is no need for requirements.txt as lambda is not going to use it and install any packages you have listed there.也不需要requirements.txt ,因为 lambda 不会使用它并安装您在此处列出的任何软件包。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “errorMessage”:“无法导入模块‘app’:没有名为‘requests’的模块”,“errorType”:“Runtime.ImportModuleError” - "errorMessage": "Unable to import module 'app': No module named 'requests'", "errorType": "Runtime.ImportModuleError" Runtime.ImportModuleError:无法导入模块(lambda) - Runtime.ImportModuleError: Unable to import module (lambda) 为什么找不到模块“请求承诺”? (运行时.ImportModuleError) - Why Cannot find module 'request-promise' ? ( Runtime.ImportModuleError) 无法导入模块“app”:使用 Chalice 在 Aws Lambda 中没有名为“app”的模块 - Unable to import module 'app': No module named 'app' in Aws Lambda using Chalice AWS Lambda 导入 psycopg2 - 无法导入模块“app”:没有名为“psycopg2._psycopg”的模块 - AWS Lambda Importing psycopg2 - Unable to import module 'app': No module named 'psycopg2._psycopg AWS Lambda Python 错误 - Runtime.ImportModuleError - AWS Lambda Python error - Runtime.ImportModuleError 无法导入模块“lambda_function”:没有名为“pymongo”的模块 - Unable to import module 'lambda_function': No module named 'pymongo' “Runtime.ImportModuleError”尝试使用层访问 AWS lambda function 中的 npm package - "Runtime.ImportModuleError" trying to access npm package in an AWS lambda function using layers AWS Lambda 层无法导入模块“lambda_function”:没有名为“pyarrow.lib”的模块 - AWS Lambda Layer Unable to import module 'lambda_function': No module named 'pyarrow.lib' AWS SAM Lambda - 无法导入模块“main”:没有名为“requests”、“msal”的模块。 使用 Azure CI/CD 的管道 - AWS SAM Lambda - Unable to import module 'main': No module named 'requests', 'msal' . pipeline using Azure CI/CD
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM