環境
- Mac OS Catalina 10.15.7
- AWS Lambda
- Serverless Framework standalone (
- Framework Core: 2.11.1 (standalone)
- Plugin: 4.1.2
- SDK: 2.3.2
- Components: 3.3.0
Serverless Framework スタンドアロンのインストール
nodeのバージョン依存に関係なく使用するため、npmでのインストールではなくスタンドアロンを使用した
Get started with Serverless Framework Open Source & AWS に記載の通り
curl -o- -L https://slss.io/install | bash
AWSのクレデンシャルの設定
AWS - Credentialsを参考にCredentialを作成し、それをローカルに適用する.
適用の方法はいくつかあるが、環境変数に設定する方法で対応した
sls plugin install -n serverless-python-requirements
serverless.ymlを作成
service: funcname
plugins:
- serverless-python-requirements
package:
individually: true
exclude:
- package.json
- package-lock.json
- ./**
custom:
pythonRequirements:
usePipenv: false
dockerizePip: true
provider:
name: aws
runtime: python3.8
stage: dev
region: ap-northeast-1
functions:
fnc:
runtime: python3.8
handler: funcname.handler
package:
include:
- "src/*.py"
dockerize Trueの場合
Dockerのインストールが必要なので、Dockerをインストールする -> 参考
packageのインストール
必要なパッケージをインストールする
serverless-python-requirements
serverless-python-requirements はpythonの依存パッケージをインストールするための仕組み
serverless.yml
と共にrequirements.txtを配置しておくと依存パッケージをまとめてLambdaにアップロードしてくれる
sls plugin install -n serverless-python-requirements
AWS Lambdaにデプロイ
sls deploy -v
# -v:ログの詳細表示
AWS Lambda削除
sls remove -v