Serverless Framework で AWS Lambda へ deploy する

Serverless Framework の aws-nodejs テンプレートを利用して、AWS Lambda へ deploy するまでの流れをご紹介します。

Serverless Framework

前提条件

$ node --version
v8.10.0

AWS CLI で複数 AWS アカウントを登録・使い分ける方法 の通り、設定しているとします。

serverless インストール 〜 deploy まで

serverless のインストールから deploy までを以下の記事を参考にやっていきます。

serverless インストール

serverless を –global でインストールします。

npm install serverless --global

serverless version 確認

インストール後、まず version を確認しましょう。

$ serverless --version
1.35.0

テンプレートからサービス作成

以下のように aws-nodejs テンプレートを指定して serverless create コマンドで service を作成します。

serverless create --template aws-nodejs

AWS Lambda へ deploy

serverless deploy コマンドで AWS Lambda へ deploy します。

$ serverless deploy --aws-profile 2nd-account
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Creating Stack...
Serverless: Checking Stack create progress...
.....
Serverless: Stack create finished...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service .zip file to S3 (17.56 MB)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
...............
Serverless: Stack update finished...
Service Information
service: aws-nodejs
stage: dev
region: us-east-1
stack: aws-nodejs-dev
api keys:
  None
endpoints:
  None
functions:
  hello: aws-nodejs-dev-hello
layers:
  None

以上、Serverless Framework の aws-nodejs テンプレートを利用して、AWS Lambda へ deploy してみた現場からお送りしました。

参考情報