:>/dev/null

ラガードエンジニアの不撓不屈の精神/unlearning/go beyond

amazon linux2でのpython3環境構築

Lambdaをpython3で書く必要があり、まずは環境構築を行った時の勉強メモ。

  • 構築手順
    • python3 install
    • pip3 install
    • reqest package作成
    • boto3 package作成
    • Token取得
      • ※取得したTokenが正常か確認
・python3 install
$ sudo yum install python36 python36-virtualenv python36-pip
$ python3 -V
Python 3.6.5

・pip3 install
install python3-pip

・reqest package
pip3 install requests -t ./
rm -rf *.dist-info bin
pip3 install pipdeptree
sudo pip3 install pipdeptree
zip -r reqest.zip ./*

・boto3 package
pip install -t ./python boto3
zip -r boto3-1.9.67.zip python
cp boto3-1.9.67.zip /home/ec2-user/

[2019.02.14 add] aws linux(ec2/旧環境)で「No package」対応
># yum install python3
>Loaded plugins: priorities, update-motd, upgrade-helper
>amzn-main/latest                            | 2.1 kB     00:00
>amzn-updates/latest                      | 2.5 kB     00:00
>21 packages excluded due to repository priority protections
>No package python3 available.
>Error: Nothing to do

・現環境確認
pip --version
・Repository確認
yum list available | grep "python" | grep "libs"
・python3インストール
yum install python36 python36-virtualenv python36-pip
pip-3.6 -V
・必要パケージ収集
mkdir lambda_test/
cd lambda_test/
pip install --upgrade pip
pip-3.6 install requests bs4 slackweb -t .
rm -rf *.dist-info *.egg-info bin
・パケージ化
zip -r scraping_pkg.zip ./*

・Token取得について
https://api.slack.com/apps/AE******/oauth? ->[OAuth&Permission] ->「Bot User OAuth Access Token」

Tokenが正常認証許可するか確認
https://slack.com/api/chat.postMessage?token=xoxb-xxxxxx-xxxxxx-xxxxxx&channel=test&text=%22Hello%22
↓結果
{"ok":true,"channel":"CERG265JT","ts":"1545287527.000100","message":{"type":"message","subtype":"bot_message","text":"\"Hello\"","ts":"1545287527.000100","username":"slack-test-func","bot_id":"BE9TMPEUQ"}}

まず、python3→Token取得まで確認した。
サーバレスアーキテクチャでLambdaを選択する場合に使えそう。

ref)
https://goodbyegangster.hatenablog.com/entry/2018/05/22/024513
https://qiita.com/SHASE03/items/16fd31d3698f207b42c9
https://qiita.com/hayao_k/items/b9750cc8fa69d0ce91b0
https://qiita.com/ykhirao/items/3b19ee6a1458cfb4ba21