这是我第一次使用无服务器又名AWS lambda
。
这是我的第一级和第二级目录树
$ 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
这是我的设置
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"
}
}
部署进行得很顺利,突然提高了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.
我在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]
我在哪里错了?
答案 0 :(得分:1)
您之所以得到502,是因为一旦与API网关一起部署,API网关就需要Lambda发出非常具体的响应,否则会抛出Malformed Lambda proxy response
,也就是502。
作为mentioned in the documentation,您应确保Lambda以以下结构(必须为JSON)返回响应:
{
"isBase64Encoded": true|false,
"statusCode": httpStatusCode,
"headers": { "headerName": "headerValue", ... },
"body": "..."
}
答案 1 :(得分:0)
根据jonvaughan移动应用程序
Another reference
这是我的工作目录结构
SELECT * FROM MY_USERS WHERE USER_ID IN (?, ?, ?, ?, ?, ? ,? ,?)