0
1

More than 3 years have passed since last update.

Serverless Frameworkを使用して AWS Lambdaにデプロイ

Posted at

環境

  • 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

参考

qiita-Serverless FrameworkでAWS Lambdaをデプロイ

0
1
1

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
1