7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Elastic Beanstalkでflaskアプリをデプロイする時にハマったことまとめ

Last updated at Posted at 2018-03-20

投稿の意義

アプリエンジニアが、初めてアプリケーションのデプロイを0から行った際にハマった事象と解決策を書く。
そして、同じように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 init時にNotAuthorizedError が出る

  • 下記XXXXの認証情報が正しいか確認する
vi ~/.aws/credentials

aws_access_key_id = XXXXXX
aws_secret_access_key = XXXXX

**eb create / deploy時にYour WSGIPath refers to a file that does not existエラーが出ている**
  • 実行ファイル名がapplication.pyになっていることを確認する
  • アプリ名がapllicationになっていることを確認する↓

AWSチュートリアルのサンプルコード
image.png

eb logsでログを確認すると、mod_wsgi “Call to 'site.addsitedir()' failed” エラーが出ている

  • mod_wsgiのバージョンを上げる↓

コンフィグファイルを作成  

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

下記を貼り付け

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

7
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?