使用Elastic Beanstalk部署Flask应用程序时沉迷于我的摘要


发布

的意义

应用程序工程师编写他第一次从头开始部署应用程序时沉迷的事件和解决方案。
而且,它还解决了那些首次在AWS EB上部署应用程序的人上瘾的问题。
(我希望您能解决它)

我做了

我基本上根据官方文档进行工作。

安装Elastic Beanstalk命令行界面(EB CLI)
https://docs.aws.amazon.com/ja_jp/elasticbeanstalk/latest/dg/eb-cli3-install.html

在AWS Elastic Beanstalk上部署Flask应用程序
https://docs.aws.amazon.com/ja_jp/elasticbeanstalk/latest/dg/create-deploy-python-flask.html

我沉迷于

eb初始化

时出现NotAuthorizedError

  • 检查以下XXXX凭据是否正确
1
2
3
4
vi ~/.aws/credentials

aws_access_key_id = XXXXXX
aws_secret_access_key = XXXXX

您的WSGIPath引用创建/部署

时不存在的文件错误

  • 确保可执行文件名为application.py
  • 确保应用程序名称为副标题↓

AWS教程示例代码
image.png

当我用eb日志检查日志时,收到mod_wsgi"调用\\'site.addsitedir()\\'失败"错误

  • 提升mod_wsgi的版本↓

创建配置文件

1
2
3
cd ~/eb-flask
mkdir .ebextensions
vi wsgi_update.config

粘贴以下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
packages:
  yum:
    git: []
    gcc-c++: []
    httpd24-devel-2.4.27-3.75.amzn1.x86_64: []

files:
  "/tmp/update-wsgi.sh" :
    mode: "000755"
    owner: root
    group: root
    content: |
      # update mod_wsgi
      cd /tmp
      wget -q "https://github.com/GrahamDumpleton/mod_wsgi/archive/4.4.21.tar.gz" && \
      tar -xzf '4.4.21.tar.gz' && \
      cd ./mod_wsgi-4.4.21 && \
      sudo ./configure --with-python=/usr/bin/python3.6 && \
      sudo make && \
      sudo make install && \
      sudo service httpd restart

commands:
  mod_wsgi_update:
    command: /tmp/update-wsgi.sh
    cwd: /tmp

参考:https://serverfault.com/questions/884469/mod-wsgi-call-to-site-addsitedir-failed-on-aws-elastic-beanstalk-python-3/885445