SAM(Serverless Application Model) を用いて構築します。
sam init
を実行しプロジェクトを作成します。
Quick Start Templates
を使用nodejs12.x
Hello World
$ sam init
Which template source would you like to use?
1 - AWS Quick Start Templates
2 - Custom Template Location
Choice: 1
Which runtime would you like to use?
1 - nodejs12.x
2 - python3.8
3 - ruby2.7
4 - go1.x
5 - java11
6 - dotnetcore3.1
7 - nodejs10.x
8 - python3.7
9 - python3.6
10 - python2.7
11 - ruby2.5
12 - java8
13 - dotnetcore2.1
Runtime: 1
Project name [sam-app]:
Cloning app templates from https://github.com/awslabs/aws-sam-cli-app-templates.git
AWS quick start application templates:
1 - Hello World Example
2 - Step Functions Sample App (Stock Trader)
3 - Quick Start: From Scratch
4 - Quick Start: Scheduled Events
5 - Quick Start: S3
6 - Quick Start: SNS
7 - Quick Start: SQS
8 - Quick Start: Web Backend
Template selection: 1
-----------------------
Generating application:
-----------------------
Name: sam-app
Runtime: nodejs12.x
Dependency Manager: npm
Application Template: hello-world
Output Directory: .
Next steps can be found in the README file at ./sam-app/README.md
HTTP APIを作成したいのでファイルを修正します。 template.yaml
というファイルがあるので、そのファイルの22行目をType: HttpApi
に変更します。 33行目の${ServerlessRestApi}
を${ServerlessHttpApi}
に変更します。
$ $ cd sam-app/ ### initを実行してできたディレクトリ
$ vi template.yaml
~~~~~~~~
22 Type: HttpApi
33 Value: !Sub "https://${ServerlessHttpApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/"
~~~~~~~~
sam build
を実行します。
$ sam build
Building function 'HelloWorldFunction'
Running NodejsNpmBuilder:NpmPack
Running NodejsNpmBuilder:CopyNpmrc
Running NodejsNpmBuilder:CopySource
Running NodejsNpmBuilder:NpmInstall
Running NodejsNpmBuilder:CleanUpNpmrc
Build Succeeded
Built Artifacts : .aws-sam/build
Built Template : .aws-sam/build/template.yaml
Commands you can use next
=========================
[*] Invoke Function: sam local invoke
[*] Deploy: sam deploy --guided
sam deploy --guided
を実行してデプロイします
デプロイが成功すると Successfully ~~~
が表示されます。
$ sam deploy --guided
~~~~~
Successfully created/updated stack - sam-app in ap-northeast-1
AWSのコンソールを確認してみます。
#aws #auth0 #amazon api gateway #jwt authorizers