Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Warning! Status check on the deployed lambda failed. A GET request to '/' yielded a 502 response code. #1358

Open
zfogg opened this issue Dec 3, 2024 · 5 comments

Comments

@zfogg
Copy link

zfogg commented Dec 3, 2024

Context

When I try to deploy or update, the process works well except for the final status check. It 502s because it can't import handler module, which is weird because that's generated by zappa not me.

The output of zappa tail:

[1733249897767] INIT_REPORT Init Duration: 2021.74 ms Phase: invoke Status: error Error Type: Runtime.ImportModuleError
[1733250008792] [ERROR] Runtime.ImportModuleError: Unable to import module 'handler': attempted relative import with no known parent package
Traceback (most recent call last):
[1733250009050] INIT_REPORT Init Duration: 2024.93 ms Phase: invoke Status: error Error Type: Runtime.ImportModuleError
[1733250072033] [ERROR] Runtime.ImportModuleError: Unable to import module 'handler': attempted relative import with no known parent package
Traceback (most recent call last):
[1733250072290] INIT_REPORT Init Duration: 1999.91 ms Phase: invoke Status: error Error Type: Runtime.ImportModuleError
[1733250135174] [ERROR] Runtime.ImportModuleError: Unable to import module 'handler': attempted relative import with no known parent package
Traceback (most recent call last):
[1733250135434] INIT_REPORT Init Duration: 1988.36 ms Phase: invoke Status: error Error Type: Runtime.ImportModuleError

Expected Behavior

It should deploy properly and be able to GET /

Actual Behavior

When it does GET to / it 502s because of an import error

Steps to Reproduce

  1. Use this code (api/app.py):
import os
from dotenv import load_dotenv
from flask import Flask, jsonify, request
from waitress import serve
from api.youtube_analyzer import YouTubeAnalyzer

# Load environment variables
load_dotenv()
api_key = os.getenv('YOUTUBE_API_KEY')

if not api_key:
    raise ValueError("Please set YOUTUBE_API_KEY in your .env file")

app = Flask(__name__)
analyzer = YouTubeAnalyzer(api_key)

@app.route('/', methods=['GET'])
def index():
    return jsonify({
        'status': 'ok'
    }), 200

@app.route('/analyze', methods=['GET'])
def analyze_channel():
    return jsonify({'status': 'ok'}), 200

if __name__ == '__main__':
    port = os.getenv('PORT', 5000)
    print(f"Starting server on http://0.0.0.0:{port}")
    serve(app, host='0.0.0.0', port=port)
  1. use these settings:
{
    "dev": {
        "app_function": "api.app.app",
        "aws_region": "us-east-1",
        "exclude": [
            "boto3",
            "dateutil",
            "botocore",
            "s3transfer",
            "concurrent"
        ],
        "profile_name": "default",
        "project_name": "ytpoppers-api",
        "runtime": "python3.12",
        "s3_bucket": "zappa-ytpoppers-api"
    }
}
  1. run zappa deploy dev

Your Environment

  • Zappa version used: latest
  • Operating System and Python version: windows, python3.12
  • The output of pip freeze:
blinker==1.9.0
cachetools==5.5.0
certifi==2024.8.30
charset-normalizer==3.4.0
click==8.1.7
colorama==0.4.6
Flask==3.0.0
google-api-core==2.23.0
google-api-python-client==2.108.0
google-auth==2.36.0
google-auth-httplib2==0.2.0
googleapis-common-protos==1.66.0
httplib2==0.22.0
idna==3.10
itsdangerous==2.2.0
Jinja2==3.1.4
MarkupSafe==3.0.2
proto-plus==1.25.0
protobuf==5.29.0
pyasn1==0.6.1
pyasn1_modules==0.4.1
pyparsing==3.2.0
python-dotenv==1.0.0
requests==2.32.3
rsa==4.9
uritemplate==4.1.1
urllib3==2.2.3
waitress==2.1.2
Werkzeug==3.1.3
{
    "dev": {
        "app_function": "api.app.app",
        "aws_region": "us-east-1",
        "exclude": [
            "boto3",
            "dateutil",
            "botocore",
            "s3transfer",
            "concurrent"
        ],
        "profile_name": "default",
        "project_name": "ytpoppers-api",
        "runtime": "python3.12",
        "s3_bucket": "zappa-ytpoppers-api"
    }
}
@zfogg
Copy link
Author

zfogg commented Dec 3, 2024

is my modular path incorrect? here's my directory structure:
image

so i have a folder/module called api, and inside of it a file/module called app, and inside of that i have a Flask app variable called app. so my module path should be api.app.app, right?

@lorodoes
Copy link

@zfogg have you been able to figure ou thte issue? I'm having a similar issue with django with the django-configuation python module.

@zfogg
Copy link
Author

zfogg commented Dec 16, 2024

@lorodoes no i haven't figured the issue out and couldn't get this project to work for me. i'm using aws sam instead.

@lorodoes
Copy link

@zfogg try adding the package in the includes in the zappa setting. Also, from what I found it's most likely because it can't figure out what your application function is the wsgi to be exact. normally it can discover it. Try adding something like this to the zappa settings (this is at least for django):

"app_function": "myproject.wsgi.application",

@lorodoes
Copy link

The include setting looks like this:

"include": [
"django-configurations",
"configurations"
],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants