我第一次玩Chalice,因为我试图将其评估为可能的替代框架,以将现有的Python Flask API从EC2迁移到Lambda。

在Amazon Linux EC2实例中,我向正在使用的virtualenv添加了一些依赖项。然后,我创建了requirements.txt:

botocore==1.7.11
chalice==1.0.2
click==6.6
docutils==0.14
jmespath==0.9.3
MySQL-python==1.2.5
PyMySQL==0.7.11
python-dateutil==2.6.1
six==1.10.0
SQLAlchemy==1.1.14
typing==3.5.3.0

然后,我尝试使用chalice deploy进行部署,并得到:
Creating deployment package.

Could not install dependencies:
MySQL-python==1.2.5
typing==3.5.3.0
You will have to build these yourself and vendor them in
the chalice vendor folder.

Your deployment will continue but may not work correctly
if missing dependencies are not present. For more information:
http://chalice.readthedocs.io/en/latest/topics/packaging.html
........

然后,我尝试遵循docs的链接,对于第一个有问题的依赖项MySQL-python==1.2.5,我执行了以下操作:
cd vendor/
pip download MySQL-python==1.2.5
pip wheel MySQL-python-1.2.5.zip
rm rm MySQL-python-1.2.5.zip
unzip MySQL_python-1.2.5-cp27-cp27mu-linux_x86_64.whl
rm MySQL_python-1.2.5-cp27-cp27mu-linux_x86_64.whl

我的供应商文件夹如下所示:
ls vendor
MySQLdb  _mysql_exceptions.py  MySQL_python-1.2.5.dist-info  _mysql.so

现在,当我运行 chalice 部署时,我得到:
(test)[ec2-user@ip-172-31-26-155 test]$ chalice deploy
Creating deployment package.

Could not install dependencies:
MySQL-python==1.2.5
You will have to build these yourself and vendor them in
the chalice vendor folder.

Your deployment will continue but may not work correctly
if missing dependencies are not present. For more information:
http://chalice.readthedocs.io/en/latest/topics/packaging.html

/home/ec2-user/test/test/local/lib/python2.7/site-packages/chalice/deploy/packager.py:110: UserWarning: Duplicate name: '_mysql.so'
  zipped.write(full_path, zip_path)
/home/ec2-user/test/test/local/lib/python2.7/site-packages/chalice/deploy/packager.py:110: UserWarning: Duplicate name: '_mysql_exceptions.py'
  zipped.write(full_path, zip_path)
/home/ec2-user/test/test/local/lib/python2.7/site-packages/chalice/deploy/packager.py:110: UserWarning: Duplicate name: 'MySQL_python-1.2.5.dist-info/RECORD'
  zipped.write(full_path, zip_path)
/home/ec2-user/test/test/local/lib/python2.7/site-packages/chalice/deploy/packager.py:110: UserWarning: Duplicate name: 'MySQL_python-1.2.5.dist-info/DESCRIPTION.rst'
  zipped.write(full_path, zip_path)
/home/ec2-user/test/test/local/lib/python2.7/site-packages/chalice/deploy/packager.py:110: UserWarning: Duplicate name: 'MySQL_python-1.2.5.dist-info/WHEEL'
  zipped.write(full_path, zip_path)
/home/ec2-user/test/test/local/lib/python2.7/site-packages/chalice/deploy/packager.py:110: UserWarning: Duplicate name: 'MySQL_python-1.2.5.dist-info/top_level.txt'
  zipped.write(full_path, zip_path)
/home/ec2-user/test/test/local/lib/python2.7/site-packages/chalice/deploy/packager.py:110: UserWarning: Duplicate name: 'MySQL_python-1.2.5.dist-info/METADATA'
  zipped.write(full_path, zip_path)
/home/ec2-user/test/test/local/lib/python2.7/site-packages/chalice/deploy/packager.py:110: UserWarning: Duplicate name: 'MySQL_python-1.2.5.dist-info/metadata.json'
  zipped.write(full_path, zip_path)
/home/ec2-user/test/test/local/lib/python2.7/site-packages/chalice/deploy/packager.py:110: UserWarning: Duplicate name: 'MySQLdb/converters.py'
  zipped.write(full_path, zip_path)
/home/ec2-user/test/test/local/lib/python2.7/site-packages/chalice/deploy/packager.py:110: UserWarning: Duplicate name: 'MySQLdb/release.py'
  zipped.write(full_path, zip_path)
/home/ec2-user/test/test/local/lib/python2.7/site-packages/chalice/deploy/packager.py:110: UserWarning: Duplicate name: 'MySQLdb/__init__.py'
  zipped.write(full_path, zip_path)
/home/ec2-user/test/test/local/lib/python2.7/site-packages/chalice/deploy/packager.py:110: UserWarning: Duplicate name: 'MySQLdb/cursors.py'
  zipped.write(full_path, zip_path)
/home/ec2-user/test/test/local/lib/python2.7/site-packages/chalice/deploy/packager.py:110: UserWarning: Duplicate name: 'MySQLdb/times.py'
  zipped.write(full_path, zip_path)
/home/ec2-user/test/test/local/lib/python2.7/site-packages/chalice/deploy/packager.py:110: UserWarning: Duplicate name: 'MySQLdb/connections.py'
  zipped.write(full_path, zip_path)
/home/ec2-user/test/test/local/lib/python2.7/site-packages/chalice/deploy/packager.py:110: UserWarning: Duplicate name: 'MySQLdb/constants/REFRESH.py'
  zipped.write(full_path, zip_path)
/home/ec2-user/test/test/local/lib/python2.7/site-packages/chalice/deploy/packager.py:110: UserWarning: Duplicate name: 'MySQLdb/constants/CLIENT.py'
  zipped.write(full_path, zip_path)
/home/ec2-user/test/test/local/lib/python2.7/site-packages/chalice/deploy/packager.py:110: UserWarning: Duplicate name: 'MySQLdb/constants/ER.py'
  zipped.write(full_path, zip_path)
/home/ec2-user/test/test/local/lib/python2.7/site-packages/chalice/deploy/packager.py:110: UserWarning: Duplicate name: 'MySQLdb/constants/FIELD_TYPE.py'
  zipped.write(full_path, zip_path)
/home/ec2-user/test/test/local/lib/python2.7/site-packages/chalice/deploy/packager.py:110: UserWarning: Duplicate name: 'MySQLdb/constants/__init__.py'
  zipped.write(full_path, zip_path)
/home/ec2-user/test/test/local/lib/python2.7/site-packages/chalice/deploy/packager.py:110: UserWarning: Duplicate name: 'MySQLdb/constants/CR.py'
  zipped.write(full_path, zip_path)
/home/ec2-user/test/test/local/lib/python2.7/site-packages/chalice/deploy/packager.py:110: UserWarning: Duplicate name: 'MySQLdb/constants/FLAG.py'
  zipped.write(full_path, zip_path)

从文档中,我不清楚我在做什么错。有人可以帮忙吗?

最佳答案

您可以从Requirements.txt中删除“MySQL-python == 1.2.5”(因为它已经存在)
在您的供应商目录中)

有关详细信息,请参阅 chalice 回购中的此issue

关于python - chalice 包装问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46382384/

10-11 07:58