1

This is my first time with serverless aka AWS lambda. Here is my directory tree 1st and 2nd level

$ tree -L 2
.
├── README.md
├── Visualization_Sarit
│   ├── BA_Read0DDataPlot1DGraph.py
│   ├── CC_ReadNew2DDataPlotLineGraph.py
│   ├── ModulesInterfaceTASK.py
│   ├── Visualization.docx
│   ├── Visualization.xlsx
│   └── inHT6Ms302
├── apps
│   ├── advanced_cases
│   ├── commons
│   ├── control_params
│   ├── device_params
│   ├── heating_params
│   ├── plasma_params
│   ├── plasma_species
│   ├── results
│   ├── scenarios
│   └── transport_params
├── experiments.py
├── f1
│   ├── README.md
│   ├── package-lock.json
│   ├── package.json
│   ├── public
│   └── src
├── ht6m
│   ├── __init__.py
│   ├── __pycache__
│   ├── api_urls.py
│   ├── celery.py
│   ├── db_routers.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── manage.py
├── media
├── requirements.in
├── requirements.txt
├── static
├── static_files
├── templates
│   ├── __init__.py
│   └── hello.html
└── zappa_settings.json

Here is my settings

settings.py

DEBUG = True

ALLOWED_HOSTS = ['*']

# Application definition

INSTALLED_APPS = [
    'django_celery_results',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django_extensions',
    'django_rq',
    'django_filters',
    'corsheaders',
    'rest_framework',
    'apps.advanced_cases',
    'apps.commons',
    'apps.control_params',
    'apps.device_params',
    'apps.heating_params',
    'apps.plasma_params',
    'apps.plasma_species',
    'apps.results',
    'apps.scenarios',
    'apps.transport_params',
]

MIDDLEWARE = [
    'corsheaders.middleware.CorsMiddleware',
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

zappa_settings.json

{
    "dev": {
        "django_settings": "ht6m.settings",
        "profile_name": "aegon",
        "project_name": "ht6minterface",
        "runtime": "python3.7",
        "s3_bucket": "zappa-20j5uvs5p",
        "aws_region": "ap-southeast-1"
    }
}

Deployment went smooth and suddenly raises 502

$ zappa deploy dev
Calling deploy for stage dev..
Creating ht6minterface-dev-ZappaLambdaExecutionRole IAM Role..
Creating zappa-permissions policy on ht6minterface-dev-ZappaLambdaExecutionRole IAM Role.
Downloading and installing dependencies..
 - psycopg2-binary==2.8.2: Downloading
100%|█████████████████████████████████████████████████████████████████████████████████████| 2.94M/2.94M [00:01<00:00, 1.95MB/s]
 - greenlet==0.4.15: Downloading
100%|██████████████████████████████████████████████████████████████████████████████████████| 42.4K/42.4K [00:00<00:00, 492KB/s]
 - gevent==1.4.0: Downloading
100%|█████████████████████████████████████████████████████████████████████████████████████| 5.44M/5.44M [00:01<00:00, 5.01MB/s]
 - cffi==1.12.3: Downloading
100%|███████████████████████████████████████████████████████████████████████████████████████| 431K/431K [00:00<00:00, 1.48MB/s]
 - sqlite==python3: Using precompiled lambda package
'python3.7'
Packaging project as zip.
Uploading ht6minterface-dev-1559645572.zip (42.2MiB)..
100%|█████████████████████████████████████████████████████████████████████████████████████| 44.2M/44.2M [00:22<00:00, 1.96MB/s]
Scheduling..
Scheduled ht6minterface-dev-zappa-keep-warm-handler.keep_warm_callback with expression rate(4 minutes)!
Uploading ht6minterface-dev-template-1559645689.json (1.6KiB)..
100%|█████████████████████████████████████████████████████████████████████████████████████| 1.65K/1.65K [00:00<00:00, 17.7KB/s]
Waiting for stack ht6minterface-dev to create (this can take a bit)..
100%|███████████████████████████████████████████████████████████████████████████████████████████| 4/4 [00:16<00:00,  5.44s/res]
Deploying API Gateway..
Error: Warning! Status check on the deployed lambda failed. A GET request to '/' yielded a 502 response code.

I don't see any error in the zappa tail

$ zappa tail
Calling tail for stage dev..
[1559645713491] Instancing..
  File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlockededdule
[1559645730278] [DEBUG] 2019-06-04T10:55:30.278Z 466c2217-3fd7-4a2e-b97c-732866c5df54 Zappa Event: {'time': '2019-06-04T10:54:50Z', 'detail-type': 'Scheduled Event', 'source': 'aws.events', 'account': '530403937392', 'region': 'ap-southeast-1', 'detail': {}, 'version': '0', 'resources': ['arn:aws:events:ap-southeast-1:530403937392:rule/ht6minterface-dev-zappa-keep-warm-handler.keep_warm_callback'], 'id': 'c2ccca98-e69a-2f19-c398-4d123d24956c', 'kwargs': {}}
[1559645730279] [DEBUG] 2019-06-04T10:55:30.279Z 466c2217-3fd7-4a2e-b97c-732866c5df54 Zappa Event: {}
[1559645731280]
[1559645970227] [DEBUG] 2019-06-04T10:59:30.227Z ad604f41-5692-47b0-8e49-894f52afc56f Zappa Event: {'time': '2019-06-04T10:58:50Z', 'detail-type': 'Scheduled Event', 'source': 'aws.events', 'account': '530403937392', 'region': 'ap-southeast-1', 'detail': {}, 'version': '0', 'resources': ['arn:aws:events:ap-southeast-1:530403937392:rule/ht6minterface-dev-zappa-keep-warm-handler.keep_warm_callback'], 'id': '166fb665-ec39-526e-6ccb-47f1d8f083d3', 'kwargs': {}}
[1559645970227] [DEBUG] 2019-06-04T10:59:30.227Z ad604f41-5692-47b0-8e49-894f52afc56f Zappa Event: {}
[1559645971229]

Where am I wrong?

6
  • Please, add your INSTALLED_APPS from settings.py Commented Jun 4, 2019 at 11:19
  • I am assuming that the app is a folder with other folders in it. All the folders have an __init__.py file inside? Commented Jun 4, 2019 at 11:35
  • I have updated my question. It does not has __init__.py in the apps. Give me a second. I will try it. Commented Jun 4, 2019 at 11:39
  • It does not work. Commented Jun 4, 2019 at 11:41
  • Is it working locally? Commented Jun 4, 2019 at 11:41

2 Answers 2

1

You're getting 502 because once deployed with API gateway, API gateway requires a very specific response from the Lambda, otherwise it will throw you a Malformed Lambda proxy response aka 502.

As mentioned in the documentation, you should make sure your Lambda is returning a response in the following structure (this must be a JSON):

{
    "isBase64Encoded": true|false,
    "statusCode": httpStatusCode,
    "headers": { "headerName": "headerValue", ... },
    "body": "..."
}
Sign up to request clarification or add additional context in comments.

Comments

0

Move the apps according to jonvaughan
Another reference

Here is my working directory structure

$ tree -L 2
.
├── README.md
├── Visualization_Sarit
│   ├── BA_Read0DDataPlot1DGraph.py
│   ├── CC_ReadNew2DDataPlotLineGraph.py
│   ├── ModulesInterfaceTASK.py
│   ├── Visualization.docx
│   ├── Visualization.xlsx
│   └── inHT6Ms302
├── __init__.py
├── __pycache__
│   ├── api_urls.cpython-36.pyc
│   ├── celery_ht6m.cpython-36.pyc
│   ├── db_routers.cpython-36.pyc
│   ├── settings.cpython-36.pyc
│   ├── urls.cpython-36.pyc
│   └── wsgi.cpython-36.pyc
├── api_urls.py
├── apps
│   ├── __init__.py
│   ├── __pycache__
│   ├── advanced_cases
│   ├── commons
│   ├── control_params
│   ├── device_params
│   ├── heating_params
│   ├── plasma_params
│   ├── plasma_species
│   ├── results
│   ├── scenarios
│   └── transport_params
├── celery_ht6m.py
├── db_routers.py
├── experiments.py
├── f1
│   ├── README.md
│   ├── package-lock.json
│   ├── package.json
│   ├── public
│   └── src
├── manage.py
├── media
├── requirements.in
├── requirements.txt
├── settings.py
├── static
├── static_files
├── templates
│   ├── __init__.py
│   └── hello.html
├── urls.py
├── wsgi.py
└── zappa_settings.json

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.