这是我第一次尝试使用zappa,但由于某种未知原因失败了。看到了其他一些类似的帖子,但它们似乎没有关联。
这是zappa_settings.json
{
"dev": {
"app_function": "app.app",
"aws_region": "ap-southeast-1",
"profile_name": "default",
"project_name": "zappa-app",
"runtime": "python3.7",
"s3_bucket": "zappa-ttsqlve2j"
}
}
这些是我运行zappo deploy dev
时的控制台日志。
Downloading and installing dependencies..
- markupsafe==1.1.1: Downloading
100%|██████████████████████████████████████| 27.5k/27.5k [00:00<00:00, 6.20MB/s]
Packaging project as zip.
Uploading zappa-app-dev-1605776315.zip (6.0MiB)..
100%|██████████████████████████████████████| 6.26M/6.26M [00:04<00:00, 1.49MB/s]
Scheduling..
Scheduled zappa-app-dev-zappa-keep-warm-handler.keep_warm_callback with expression rate(4 minutes)!
Uploading zappa-app-dev-template-1605776326.json (1.6KiB)..
100%|██████████████████████████████████████| 1.63k/1.63k [00:00<00:00, 4.49kB/s]
Waiting for stack zappa-app-dev to create (this can take a bit)..
75%|█████████████████████████████████ | 3/4 [00:12<00:04, 4.12s/res]
Deploying API Gateway..
Error: Warning! Status check on the deployed lambda failed. A GET request to '/' yielded a 500 response code.
以下是我从zappa tail
获得的选定日志。
Calling tail for stage dev..
[1605763766887] /var/runtime/botocore/vendored/requests/__init__.py:91: RequestsDependencyWarning: urllib3 (1.26.2) or chardet (3.0.4) doesn't match a supported version!
[1605763766887] RequestsDependencyWarning)
[1605763767181] Instancing..
import cv2ask/app.py", line 9, in <module>19, in _call_with_frames_removeddule
[1605763829365] [DEBUG] 2020-11-19T05:30:29.365Z f468bc46-eada-4ce1-9cd5-e544e15cb8f1 Zappa Event: {'time': '2020-11-19T05:29:09Z', 'detail-type': 'Scheduled Event', 'source': 'aws.events', 'account': 'xxx', 'region': 'ap-southeast-1', 'detail': {}, 'version': '0', 'resources': ['arn:aws:events:ap-southeast-1:xxx:rule/zappa-app-dev-zappa-keep-warm-handler.xxx'], 'id': '325e4bdc-0ce8-373f-c1f9-7384ad9cc278', 'kwargs': {}}
[1605763829365] [DEBUG] 2020-11-19T05:30:29.365Z f468bc46-eada-4ce1-9cd5-e544e15cb8f1 Zappa Event: {}
[1605764006219] [DEBUG] 2020-11-19T05:33:26.219Z 03c0312c-2ae5-48d3-b447-7154ce9d9322 Zappa Event: {'time': '2020-11-19T05:33:09Z', 'detail-type': 'Scheduled Event', 'source': 'aws.events', 'account': 'xxx', 'region': 'ap-southeast-1', 'detail': {}, 'version': '0', 'resources': ['arn:aws:events:ap-southeast-1:xxx:rule/zappa-app-dev-zappa-keep-warm-handler.xxx], 'id': 'b99799b3-a358-b580-845b-bae3b3e4c598', 'kwargs': {}}
这是我的flask应用程序app.py
的截断版本,其中包括一些图像处理任务,然后上传到S3&发电机数据库。
import base64
import json
import os
import traceback
import boto3
import cv2
import requests
from flask import Flask, request
from PIL import Image
import config
from utils_image import draw_on_image, encode_image, json2array_yolo
from utils_s3 import download_file, s3_upload
app = Flask(__name__)
# set up aws permissions
s3 = boto3.resource('s3',
aws_access_key_id=config.AWS_ACCESS_KEY_ID,
aws_secret_access_key=config.AWS_SECRET_ACCESS_KEY)
my_bucket = s3.Bucket(config.S3_BUCKETNM)
dynamo = boto3.resource('dynamodb',
region_name=config.REGION,
aws_access_key_id=config.AWS_ACCESS_KEY_ID,
aws_secret_access_key=config.AWS_SECRET_ACCESS_KEY)
table = dynamo.Table(config.DYNAMODB_TABLENM)
@app.route('/', methods=["POST"])
def intermediate():
try:
json_input = request.json
# Do some image processing
# upload image to S3
# upload processing json results to dynamoDB
return "OK"
except:
return str(traceback.format_exc())
if __name__ == "__main__":
app.run(host='0.0.0.0')
糟糕的是,我意识到我的venv中有一些python库没有正确安装,这导致网关无法启动。