表題の通り、最速でデプロイまでやる。Node.js 12.xのランタイムを使用します。
前提知識
Serverless Framework
サーバレスなアプリケーションの構成管理、デプロイをするためのツール。

Serverless: Zero-Friction Serverless Apps On AWS Lambda & Beyond.
Easily build auto-scaling, low-overhead applications on AWS Lambda, API Gateway, DynamoDB, and other managed services wi...
準備
$ npm install -g serverless実装
1. プロジェクトの作成
$ serverless create --template aws-nodejs --name my-project --path my-project
...
$ cd my-project
$ ls
handler.js serverless.ymlプロジェクトを作成すると、2つのファイルが生成されます。
それぞれの各ファイルの内容はこんな感じです。
'use strict';
module.exports.hello = async event => {
return {
statusCode: 200,
body: JSON.stringify(
{
message: 'Go Serverless v1.0! Your function executed successfully!',
input: event,
},
null,
2
),
};
// (コメント部省略)
};# (コメント部省略)
service: my-project
# (コメント部省略)
provider:
name: aws
runtime: nodejs12.x
# (コメント部省略)
functions:
hello:
handler: handler.hello
# (コメント部省略)2. 最も単純なJSONを返すAPIを実装する
handler.jsに書いてある内容を返すだけのAPIなら、serverless.ymlを少しいじるだけで実装できます。
(省略)
provider:
name: aws
runtime: nodejs12.x
+ region: ap-northeast-1
+ profile: test
(省略)
functions:
hello:
handler: handler.hello
+ events:
+ - http: GET hello
(省略)注意:AWSにデプロイするためのprofileです。使用するものを~/.aws/credentialsから選びます。(今回はtest)
credentialについては、公式とか参照:
Configuring settings for the AWS CLI - AWS Command Line Interface
AWS CLI が AWS とやり取りするのに使用する設定を構成します。
3. デプロイ
$ serverless deploy
(省略)
api keys:
None
endpoints:
GET - https://(ランダム).execute-api.ap-northeast-1.amazonaws.com/dev/hello
(省略)これで完成です。https://(ランダム).execute-api.ap-northeast-1.amazonaws.com/dev/helloにアクセスすると、handler.jsの内容がJSON形式で返ってきます。
まとめ
超簡単!


