Help us understand the problem. What is going on with this article?

AWS LambdaのServerlessでpythonライブライをデプロイする方法

More than 1 year has passed since last update.

既存ディレクトリ構成

my_prj
|
├── src
|    ├── lambda
|    |     └── lambda_function.py
|    ├── api
|    |     └── api.py
|    |
|    ├──requirements.txt

必要なlibを requirements.txtにまとめる

requirements.txt
boto3==1.4.7
requests==2.18.4 

libインストール

$ pip install -r requirements.txt -t /Users/user/git/my_prj/src/lib

libインストール後ディレクトリ構成

my_prj
|
├── src
|    ├── lambda
|    |     └── lambda_function.py
|    ├── api
|    |     └── api.py
|    |
|    ├──requirements.txt
|    |
|    ├──lib
|    |    └── boto3
|    |          └── ...
|    |    └── requests
|    |          └── ...

deploy

sls deploy --region us-east-1

その他

もしlibのrequests中から ImportError: No module named urllib3 などが発生する場合
requestsのlib中に urllib3をインストールして、import先を以下のように変更する必要がある

import urllib3
↓↓↓
from .packages import urllib3

他にもImportError: No module named urllib3場合はインストール後import先を書き変える必要がある

namkim
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした