0
0

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.

S3を使わずにEC2のストレージを利用して、ファイルを保存する

Last updated at Posted at 2020-01-20

某expertスクールを卒業後、同じようなやり方で簡易的にpythonでapiをアップロードしようとしたら、権限周りで失敗したので備忘録として

EC2の種類

簡易的にpythonのapiを作成するため、S3を使わずストレージ中にapiで出てきたファイルを保存します。

  • tタイプ
  • ubuntu 18.04

EC2ログイン後

スクールのカリキュラムでは、/var/www/を作成して、その中にアプリを入れていましたが、それでは権限周りでエラーが出てしまうので、ログイン後のhome/ubuntu/直下にgit cloneしましょう。

$ ssh -i /path/my-key-pair.pem ubuntu@x.xxx.xxx.xxx(IPv4アドレス)
# ユーザー名部分はubuntuなので注意(ec2-userではない)

(ログイン後)
$ git clone https://github.com/yyuu/pyenv.git ~/.pyenv
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
$ source ~/.bash_profile

$ sudo apt-get install git gcc make openssl libssl-dev libbz2-dev libreadline-dev libsqlite3-dev zlib1g-dev
$ pyenv install 3.6.2(ここでpythonのバージョンを選ぶ)
$ pyenv global 3.6.2
$ pyenv rehash

$ apt-get -y update
$ apt-get install -y --fix-missing
$ apt-get install build-essential
$ apt-get install software-properties-common
$ git clone クローン元のURL

apiをバックグラウンドで起動

通常通りにpython run.appすると、PCを閉じたり、EC2をログアウトした際にアプリもとまってしまうため、下記コマンドでバックグラウンドで起動します。

$ nohup python main.py &
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?