云原生-通过zappa 部署flask人脸识别应用到aws lambda
要实践这个主题首先你先准备下环境:1. python3.X ,对应 pip,python3-venv(我的是3.8.5)2. 配置awscli (参考这里)3. git 环境进入正题:1. 下载应用代码。#下载这次部署的demo ,python flask,face_recognition代码 来检查人脸的相识度$mkdir /opt/tech$cd /opt/tech$root@VM-0-3-u
·
要实践这个主题首先你先准备下环境:
1. python3.X ,对应 pip,python3-venv(我的是3.8.5)
2. 配置awscli (参考这里)
3. git 环境
进入正题:
1. 下载应用代码。
#下载这次部署的demo ,python flask,face_recognition代码 来检查人脸的相识度
$mkdir /opt/tech
$cd /opt/tech
$root@VM-0-3-ubuntu:/opt/tech# git clone -b master https://github.com/AngusZhu/flaskdemo.git
Cloning into 'flaskdemo'...
remote: Enumerating objects: 11, done.
remote: Counting objects: 100% (11/11), done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 11 (delta 0), reused 8 (delta 0), pack-reused 0
Unpacking objects: 100% (11/11), done.
$tree ./
./
├── flaskdemo.py
├── requirements.txt
├── templates
│ └── upload.html
└── zappa_settings.json
2. 安装python虚拟隔离环境
$python3 -m venv .env
#然后激活,执行后,会多一个.env目录,这个目录下是虚拟的环境
$source .env/bin/activate
3. 安装依赖
#查看依赖的文件
$more requirements.txt
flask
zappa
face_recognition
#安装依赖
$pip3 install -r requirements.txt
#安装后,可以看到有以下文件及目录
$cd .env && ls
bin include lib pyvenv.cfg
#.env/lib/python3.8/site-packages 目录下,可以看到依赖已经安装上了
$ ls zappa* face_recognition flask*
face_recognition:
__init__.py __pycache__ api.py face_detection_cli.py face_recognition_cli.py
flask:
__init__.py __pycache__ app.py cli.py ctx.py globals.py json sessions.py templating.py views.py
__main__.py _compat.py blueprints.py config.py debughelpers.py helpers.py logging.py signals.py testing.py wrappers.py
zappa:
__init__.py async.py cli.py ext letsencrypt.py policies.py wsgi.py
__pycache__ asynchronous.py core.py handler.py middleware.py utilities.py
zappa-0.52.0.dist-info:
INSTALLER LICENSE METADATA RECORD WHEEL entry_points.txt top_level.txt
4. 初始化zappa
$zappa init
███████╗ █████╗ ██████╗ ██████╗ █████╗
╚══███╔╝██╔══██╗██╔══██╗██╔══██╗██╔══██╗
███╔╝ ███████║██████╔╝██████╔╝███████║
███╔╝ ██╔══██║██╔═══╝ ██╔═══╝ ██╔══██║
███████╗██║ ██║██║ ██║ ██║ ██║
╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝
Welcome to Zappa!
Zappa is a system for running server-less Python web applications on AWS Lambda and AWS API Gateway.
This `init` command will help you create and configure your new Zappa deployment.
Let's get started!
按引导配置后,生成类似配置zappa_settings.json
$more zappa_settings.json
{
"dev": {
"app_function": "flaskdemo.app",
"aws_region": "ap-northeast-1",
"profile_name": "default",
"project_name": "flaskdemo",
"runtime": "python3.8",
"s3_bucket": "angus-serverless"
}
}
5. 部署应用到亚马逊 serverless
首次部署,dev 对应刚才对应的zappa 里面的配置
$zappa deploy dev
后续更新
$zappa update dev
$部署后可以通过Zappa tail 查看部署日志
$zappa tail
6. 成功,有类似这样的提示
7. 跑一下看下
结果意外的时,程序看何广智,还真跟杰伦有点像,CXK就不像了。
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
已为社区贡献2条内容
所有评论(0)