サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon...

55

Transcript of サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon...

Page 1: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理
Page 2: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

サーバーレスアプリケーション開発環境

鈴木哲詩

アマゾンウェブサービスジャパン

技術本部ソリューションアーキテクト

Twitterハッシュタグ #AWSInnovate

Page 3: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

想定オーディエンス

• サーバーレスの概要を理解しているがアプリケーション開発はこれから始める方

• ソフトウェアエンジニアではあるがサーバーレスアプリケーションの開発はこれから始める方

• サーバーレスについてもアプリケーション開発についてもこれから学習する予定である方

Page 4: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Agenda

• サーバーレスとは

• 開発環境

• エディタや IDE

• 開発支援ソリューション

• フレームワーク

• 開発の生産性をより向上させるために

• CI/CD

Page 5: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Page 6: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

サーバーレスとは

サーバーまたはクラスターのプロビジョニング、パッチ適用、オペレーティングシステムのメンテナンス、キャパシティーのプロビジョニングといったインフラストラクチャの管理が不要

Amazon Simple Queue Service

Amazon PersonalizeAmazon CloudWatch

Amazon Cognito

AWS Systems Manager

Amazon API GatewayAmazon DynamoDB

AWS Lambda

AWS AppSync

Amazon QuickSight Amazon Kinesis

AWS Step Functions

Amazon Simple Notification Service

Amazon Simple Storage Service

Amazon Athena

Page 7: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

サーバーレスの利点

サーバーの管理が不要

柔軟なスケーリング

価値に対する支払い

自動化された高可用性

• サーバーのプロビジョニングやメンテナンスが不要

• 保守および管理が必要なソフトウェアあるいはランタイムのインストールが不要

• 自動的にスケーリング• スループットやメモリなどで切り替えて容

量を調整しスケーリング

• スループットや実行時間に対する課金

• 組み込み済みの可用性と耐障害性機能• サービスがデフォルトで提供するため設計

不要

https://aws.amazon.com/jp/serverless/

Page 8: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

動的 Web / モバイルバックエンド

https://aws.amazon.com/jp/serverless/patterns/serverless-pattern/

インタラクティブモバイル 業務系 API / グループ企業間 API 配信系・インタラクティブ API

画像処理 / シンプルなデータ加工 分散並列処理 イベント駆動の業務処理連携 アプリフロー処理

流入データの連続処理 IoT バックエンド チャットボット / Alexa スキル データ変更トリガー処理

ログデータ収集処理 データレイクからのデータ加工 機械学習/ETLデータパイプライン スケジュール・ジョブ/CRON

代表的な適用シーン/ユースケースと実装形

Page 9: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Page 10: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

サーバーレスアプリケーション開発とは

• 課題に対してサーバーレスアーキテクチャがソリューションとなりうることを確認

• どのようにサーバーレスサービスを構成するのか定義/管理

• AWS Lambda を使ってビジネスロジックを実装

• デプロイメントなどのアプリケーションのライフサイクル管理

Page 11: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWS Lambdaで標準利用可能な言語ランタイム

• .NET Core 2.1 (C#/PowerShell)

• Go 1.x

• Java 8

• Node.js 8.10, 10.x

• Python 2.7, 3.6, 3.7

• Ruby 2.5

Page 12: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWSマネジメントコンソールで開発

• 最もシンプルで手軽な開発手法

• まずは試してみよう

• 視覚的にアプリケーションの構成を管理

• しかしながらデメリットも

• アプリケーションが大きくなると編集出来ないAWS Lambda

Page 13: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWSマネジメントコンソールで開発

• 最もシンプルで手軽な開発手法

• まずは試してみよう

• 視覚的にアプリケーションの構成を管理

• しかしながらデメリットも

• アプリケーションが大きくなると編集出来ない

https://aws.amazon.com/getting-started/tutorials/run-serverless-code/

Page 14: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWSマネジメントコンソールで開発

• 最もシンプルで手軽な開発手法

• まずは試してみよう

• 視覚的にアプリケーションの構成を管理

• しかしながらデメリットも

• アプリケーションが大きくなると編集出来ない

Page 15: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWSマネジメントコンソールで開発

• 最もシンプルで手軽な開発手法

• まずは試してみよう

• 視覚的にアプリケーションの構成を管理

• しかしながらデメリットも

• アプリケーションが大きくなると編集出来ない

Page 16: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWS Cloud9で開発

• AWS 提供の統合開発環境

• 実装、ターミナルからのコマンド操作

• 雛形からプロジェクトを生成出来る

• Node.js 8.10, Python 2.7, Python 3.6

• ローカル実行とデバッグ

• Node.js, Python のみ

• デプロイ

AWS Cloud9

https://docs.aws.amazon.com/ja_jp/cloud9/latest/user-guide/tutorial-lambda.html

Page 17: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWS Cloud9で開発

• AWS 提供の統合開発環境

• 実装、ターミナルからのコマンド操作

• 雛形からプロジェクトを生成出来る

• Node.js 8.10, Python 2.7, Python 3.6

• ローカル実行とデバッグ

• Node.js, Python のみ

• デプロイ https://docs.aws.amazon.com/ja_jp/cloud9/latest/user-guide/tutorial-lambda.html

Page 18: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWS Cloud9で開発

• AWS 提供の統合開発環境

• 実装、ターミナルからのコマンド操作

• 雛形からプロジェクトを生成出来る

• Node.js 8.10, Python 2.7, Python 3.6

• ローカル実行とデバッグ

• Node.js, Python のみ

• デプロイ https://docs.aws.amazon.com/ja_jp/cloud9/latest/user-guide/tutorial-lambda.html

Page 19: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWS Cloud9で開発

• AWS 提供の統合開発環境

• 実装、ターミナルからのコマンド操作

• 雛形からプロジェクトを生成出来る

• Node.js 8.10, Python 2.7, Python 3.6

• ローカル実行とデバッグ

• Node.js, Python のみ

• デプロイ https://docs.aws.amazon.com/ja_jp/cloud9/latest/user-guide/tutorial-lambda.html

Page 20: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWS Cloud9で開発

• AWS 提供の統合開発環境

• 実装、ターミナルからのコマンド操作

• 雛形からプロジェクトを生成出来る

• Node.js 8.10, Python 2.7, Python 3.6

• ローカル実行とデバッグ

• Node.js, Python のみ

• デプロイ https://docs.aws.amazon.com/ja_jp/cloud9/latest/user-guide/tutorial-lambda.html

Page 21: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWS Cloud9で開発

• AWS 提供の統合開発環境

• 実装、ターミナルからのコマンド操作

• 雛形からプロジェクトを生成出来る

• Node.js 8.10, Python 2.7, Python 3.6

• ローカル実行とデバッグ

• Node.js, Python のみ

• デプロイ https://docs.aws.amazon.com/ja_jp/cloud9/latest/user-guide/tutorial-lambda.html

Page 22: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWS Toolkit 対応 IDE/エディタ

対応IDE/エディタ

PyCharm (Python)

IntelliJ (Java)

Eclipse (Java)

Visual Studio (.NET)

Visual Studio Code (.NET, Node.js, Python)

• AWS Toolkit とは

• AWS 上で稼働させるためのアプリケーションの作成を支援するIDE/エディタ用プラグイン

• What for Serverless?

• 雛形からプロジェクトを作成

• ステップ実行などのデバッグ支援

• IDE/エディタからのデプロイ

Page 23: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWS Toolkit 対応 IDE/エディタ

• What for Serverless?

• 雛形からプロジェクトを作成

• ステップ実行などのデバッグ支援

• IDE/エディタからのデプロイ

Page 24: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWS Toolkit 対応 IDE/エディタ

• What for Serverless?

• 雛形からプロジェクトを作成

• ステップ実行などのデバッグ支援

• IDE/エディタからのデプロイ

Page 25: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWS Toolkit 対応 IDE/エディタ

• What for Serverless?

• 雛形からプロジェクトを作成

• ステップ実行などのデバッグ支援

• IDE/エディタからのデプロイ

Page 26: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWS Toolkit 対応 IDE/エディタ

• What for Serverless?

• 雛形からプロジェクトを作成

• ステップ実行などのデバッグ支援

• IDE/エディタからのデプロイ

Page 27: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

AWS Toolkit 対応 IDE/エディタ

• What for Serverless?

• 雛形からプロジェクトを作成

• ステップ実行などのデバッグ支援

• IDE/エディタからのデプロイ

Page 28: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

使い慣れたIDE/エディタで開発

Page 29: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

開発環境まとめ

• AWS マネジメントコンソールでの開発は “試してみる” までにしよう

• Cloud9 や Toolkit を活用することで開発生産性向上の助けとなる

• 使い慣れたIDE/エディタを使って開発することももちろん可能

• ただし Toolkit などの支援がない場合はデバッグやデプロイを別の手段で行う必要がある

Page 30: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Page 31: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

サーバーレス関連フレームワーク

• 生産性と保守性の向上に寄与

• AWS がご提供するフレームワーク

• Serverless Application Model (SAM)

• Chalice, Amplify, Serverless Express, Serverless Java Container, など

• サードパーティのフレームワーク

• Apex, Claudia.js, Serverless Framework, Sparta, Zappa, など

Page 32: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Serverless Application Model (SAM)

• SAM Template

• AWS CloudFormation 拡張

• サーバーレスアプリケーションの構成を宣言的に記述

• SAM CLI

• アプリケーションの雛形生成

• ローカル実行

• デプロイ

Page 33: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Serverless Application Model (SAM)

• SAM Template

• AWS CloudFormation 拡張

• サーバーレスアプリケーションの構成を宣言的に記述

• SAM CLI

• アプリケーションの雛形生成

• ローカル実行

• デプロイ

Page 34: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

SAM – Sample Node.js Project

$ sam init --runtime nodejs

[+] Initializing project structure...

Project generated: ./sam-app

Steps you can take next within the project folder

===================================================

[*] Invoke Function: sam local invoke HelloWorldFunction --event event.json

[*] Start API Gateway locally: sam local start-api

Read sam-app/README.md for further instructions

[*] Project initialization is now complete

$ tree -C sam-app/

sam-app/

├── README.md

├── event.json

├── hello-world

│ ├── app.js

│ ├── package.json

│ └── tests

│ └── unit

│ └── test-handler.js

└── template.yaml

3 directories, 6 files

https://docs.aws.amazon.com/serverless-application-

model/latest/developerguide/serverless-sam-cli-install.html

Page 35: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

SAM – Sample Node.js Project

$ sam init --runtime nodejs

[+] Initializing project structure...

Project generated: ./sam-app

Steps you can take next within the project folder

===================================================

[*] Invoke Function: sam local invoke HelloWorldFunction --event event.json

[*] Start API Gateway locally: sam local start-api

Read sam-app/README.md for further instructions

[*] Project initialization is now complete

$ tree -C sam-app/

sam-app/

├── README.md

├── event.json

├── hello-world

│ ├── app.js

│ ├── package.json

│ └── tests

│ └── unit

│ └── test-handler.js

└── template.yaml

3 directories, 6 files

Page 36: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

SAM – Sample Node.js Project

$ sam init --runtime nodejs

[+] Initializing project structure...

Project generated: ./sam-app

Steps you can take next within the project folder

===================================================

[*] Invoke Function: sam local invoke HelloWorldFunction --event event.json

[*] Start API Gateway locally: sam local start-api

Read sam-app/README.md for further instructions

[*] Project initialization is now complete

$ tree -C sam-app/

sam-app/

├── README.md

├── event.json

├── hello-world

│ ├── app.js

│ ├── package.json

│ └── tests

│ └── unit

│ └── test-handler.js

└── template.yaml

3 directories, 6 files

Page 37: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

SAM – Sample Node.js Project

$ sam init --runtime nodejs

[+] Initializing project structure...

Project generated: ./sam-app

Steps you can take next within the project folder

===================================================

[*] Invoke Function: sam local invoke HelloWorldFunction --event event.json

[*] Start API Gateway locally: sam local start-api

Read sam-app/README.md for further instructions

[*] Project initialization is now complete

$ tree -C sam-app/

sam-app/

├── README.md

├── event.json

├── hello-world

│ ├── app.js

│ ├── package.json

│ └── tests

│ └── unit

│ └── test-handler.js

└── template.yaml

3 directories, 6 files

exports.lambdaHandler = async (event, context) => {try {

// const ret = await axios(url);response = {

'statusCode': 200,'body': JSON.stringify({

message: 'hello world’,// location: ret.data.trim()

})}

} catch (err) {console.log(err);return err;

}

return response};

Page 38: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

SAM – Sample Node.js Project

$ sam init --runtime nodejs

[+] Initializing project structure...

Project generated: ./sam-app

Steps you can take next within the project folder

===================================================

[*] Invoke Function: sam local invoke HelloWorldFunction --event event.json

[*] Start API Gateway locally: sam local start-api

Read sam-app/README.md for further instructions

[*] Project initialization is now complete

$ tree -C sam-app/

sam-app/

├── README.md

├── event.json

├── hello-world

│ ├── app.js

│ ├── package.json

│ └── tests

│ └── unit

│ └── test-handler.js

└── template.yaml

3 directories, 6 files

$ sam local invoke HelloWorldFunction --event event.json2019-09-08 16:46:42 Invoking app.lambdaHandler (nodejs10.x)2019-09-08 16:46:42 Found credentials in shared credentials file: ~/.aws/credentials

Fetching lambci/lambda:nodejs10.x Docker container image......2019-09-08 16:46:48 Mounting /Users/**********/src/sam-app/hello-world as /var/task:ro,delegated inside runtime containerSTART RequestId: 52fdfc07-2182-154f-163f-5f0f9a621d72 Version: $LATESTEND RequestId: 52fdfc07-2182-154f-163f-5f0f9a621d72REPORT RequestId: 52fdfc07-2182-154f-163f-5f0f9a621d72 Duration: 13.41 ms Billed Duration: 100 msMemory Size: 128 MB Max Memory Used: 42 MB{"statusCode":200,"body":"{¥"message¥":¥"hello world¥"}"}

Page 39: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

SAM – Sample Node.js Project

$ sam init --runtime nodejs

[+] Initializing project structure...

Project generated: ./sam-app

Steps you can take next within the project folder

===================================================

[*] Invoke Function: sam local invoke HelloWorldFunction --event event.json

[*] Start API Gateway locally: sam local start-api

Read sam-app/README.md for further instructions

[*] Project initialization is now complete

$ tree -C sam-app/

sam-app/

├── README.md

├── event.json

├── hello-world

│ ├── app.js

│ ├── package.json

│ └── tests

│ └── unit

│ └── test-handler.js

└── template.yaml

3 directories, 6 files

$ sam local start-api2019-09-08 16:59:21 Mounting HelloWorldFunction at http://127.0.0.1:3000/hello [GET]2019-09-08 16:59:21 You can now browse to the above endpoints to invoke your functions. You do not need to restart/reload SAM CLI while working on your functions, changes will be reflected instantly/automatically. You only need to restart SAM CLI if you update your AWS SAM template2019-09-08 16:59:21 * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)

Page 40: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

SAM – Sample Node.js Project

$ sam init --runtime nodejs

[+] Initializing project structure...

Project generated: ./sam-app

Steps you can take next within the project folder

===================================================

[*] Invoke Function: sam local invoke HelloWorldFunction --event event.json

[*] Start API Gateway locally: sam local start-api

Read sam-app/README.md for further instructions

[*] Project initialization is now complete

$ tree -C sam-app/

sam-app/

├── README.md

├── event.json

├── hello-world

│ ├── app.js

│ ├── package.json

│ └── tests

│ └── unit

│ └── test-handler.js

└── template.yaml

3 directories, 6 files

$ sam local start-api2019-09-08 16:59:21 Mounting HelloWorldFunction at http://127.0.0.1:3000/hello [GET]2019-09-08 16:59:21 You can now browse to the above endpoints to invoke your functions. You do not need to restart/reload SAM CLI while working on your functions, changes will be reflected instantly/automatically. You only need to restart SAM CLI if you update your AWS SAM template2019-09-08 16:59:21 * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)

019-09-08 16:59:54 Invoking app.lambdaHandler (nodejs10.x)2019-09-08 16:59:54 Found credentials in shared credentials file: ~/.aws/credentials

Fetching lambci/lambda:nodejs10.x Docker container image......2019-09-08 16:59:59 Mounting /Users/**********/src/sam-app/hello-world as /var/task:ro,delegated inside runtime containerSTART RequestId: 52fdfc07-2182-154f-163f-5f0f9a621d72 Version: $LATESTEND RequestId: 52fdfc07-2182-154f-163f-5f0f9a621d72REPORT RequestId: 52fdfc07-2182-154f-163f-5f0f9a621d72 Duration: 19.09 ms Billed Duration: 100 msMemory Size: 128 MB Max Memory Used: 42 MB2019-09-08 17:00:00 No Content-Type given. Defaulting to 'application/json'.2019-09-08 17:00:00 127.0.0.1 - - [08/Sep/2019 17:00:00] "GET /hello HTTP/1.1" 200 -

$ curl 127.0.0.1:3000/hello{"message":"hello world"}

Page 41: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

SAM – Sample Node.js Project

$ sam init --runtime nodejs

[+] Initializing project structure...

Project generated: ./sam-app

Steps you can take next within the project folder

===================================================

[*] Invoke Function: sam local invoke HelloWorldFunction --event event.json

[*] Start API Gateway locally: sam local start-api

Read sam-app/README.md for further instructions

[*] Project initialization is now complete

$ tree -C sam-app/

sam-app/

├── README.md

├── event.json

├── hello-world

│ ├── app.js

│ ├── package.json

│ └── tests

│ └── unit

│ └── test-handler.js

└── template.yaml

3 directories, 6 files

describe('Tests index', function () {it('verifies successful response', async () => {

const result = await app.lambdaHandler(event, context)

expect(result).to.be.an('object’);expect(result.statusCode).to.equal(200);expect(result.body).to.be.an('string');

let response = JSON.parse(result.body);

expect(response).to.be.an('object’);expect(response.message).to.be.equal("hello world");// expect(response.location).to.be.an("string");

});});

Page 42: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

SAM – Sample Node.js Project

$ sam init --runtime nodejs

[+] Initializing project structure...

Project generated: ./sam-app

Steps you can take next within the project folder

===================================================

[*] Invoke Function: sam local invoke HelloWorldFunction --event event.json

[*] Start API Gateway locally: sam local start-api

Read sam-app/README.md for further instructions

[*] Project initialization is now complete

$ tree -C sam-app/

sam-app/

├── README.md

├── event.json

├── hello-world

│ ├── app.js

│ ├── package.json

│ └── tests

│ └── unit

│ └── test-handler.js

└── template.yaml

3 directories, 6 files

describe('Tests index', function () {it('verifies successful response', async () => {

const result = await app.lambdaHandler(event, context)

expect(result).to.be.an('object’);expect(result.statusCode).to.equal(200);expect(result.body).to.be.an('string');

let response = JSON.parse(result.body);

expect(response).to.be.an('object’);expect(response.message).to.be.equal("hello world");// expect(response.location).to.be.an("string");

});});

$ cd hello-world/$ npm installnpm notice created a lockfile as package-lock.json. You should commit this file.added 129 packages from 540 contributors and audited 247 packages in 6.19sfound 0 vulnerabilities

$ npm run test

> [email protected] test /Users/**********/src/sam-app/hello-world> mocha tests/unit/

Tests index✓ verifies successful response

1 passing (13ms)

Page 43: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

SAM サンプルプロジェクトまとめ

• ランタイムを指定してサンプルプロジェクトを生成出来る

• dotnetcore2.1, dotnetcore, ruby2.5, dotnetcore2.0, go, nodejs6.10, go1.x, java8, ruby, python3.6, nodejs10.x, dotnet, python2.7, dotnetcore1.0, java, python, nodejs8.10, python3.7, nodejs

• すぐに実行可能なサンプル実装とユニットテストを含む

• SAM テンプレートも同時に生成される

• このテンプレートを使って AWS CloudFormation Stack を作ってすぐにデプロイ可能

• より詳細な情報は AWS Black Belt Online Seminar で

https://www.youtube.com/watch?v=xQbLiqkI1Mw

Page 44: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

フレームワークまとめ

• 採用することで生産性と保守性の向上に期待出来る

• 使い慣れた開発環境と組み合わせて利用することが出来る

• 用途ごとに様々な実装がある

• 特定言語型

• 処理層特化型

• フロントエンド: AWS Amplify など

• バックエンド :AWS Serverless Express, AWS Chalice など

Page 45: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Page 46: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

アプリケーションのリリースサイクル

• Cloud9, SAM, AWS Toolkit などを用いれば開発環境から実際にデプロイすることも可能だがいくつかの課題を孕む

• 開発者全員が強い権限を持っていなければならない

• 誰でもどの環境にでもデプロイ出来てしまう

• 実践的なリリースサイクルにおいて考慮すべきこと

• 権限を適切に統制する

• 可能な限り自動化する

Page 47: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

リリースプロセスに求められる 4 つのフェーズ

• 他のシステムとの統合テスト• ロードテスト• UIテスト• 侵入テスト

Source Build Test Deploy

• ソースコード管理• バージョン管理• ブランチ管理• ピアレビュー

• コンパイル• ユニットテスト• スタイルチェック• コードメトリック• コンテナイメージの作成

• テスト環境にデプロイ• 本番環境にデプロイ

Page 48: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

リリースプロセスに求められる 4 つのフェーズ

• 他のシステムとの統合テスト• ロードテスト• UIテスト• 侵入テスト

Source Build Test Deploy

• ソースコード管理• バージョン管理• ブランチ管理• ピアレビュー

• コンパイル• ユニットテスト• スタイルチェック• コードメトリック• コンテナイメージの作成

• テスト環境にデプロイ• 本番環境にデプロイ

Page 49: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

リリースプロセスのレベル

Source Build Test Deploy

継続的インテグレーション (CI)

継続的デリバリ (CD)

継続的デプロイメント (CD)

承認してからリリース

Page 50: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

[OPS4] デプロイのリスクをどのように軽減していますか?

□デプロイ失敗時のシナリオを計画している(切り戻しなど)

□変更内容を事前にテストし、その結果を確認している

□デプロイ管理システムを使用している

□限定的なデプロイでのテストを実施している(カナリアテストやワンボックスデプロイなど)

□ロールバック出来るように、(既存環境とは異なる)平行環境にデプロイしている

□トラブル発生に備えて、デプロイは「頻繁に」「小さく」「可逆」に実施している

□ CI(継続的インテグレーション)ツールなどを用いて、ビルド、デプロイ、テストを自動化

している

□テストとロールバックを自動化している

AWS Well-Architected Framework

Page 51: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Source Build Test Deploy

CI/CD の適用を容易にする AWS Code シリーズ

AWS CodePipeline

AWS CodeCommit AWS CodeBuild

AWS CodeStar

AWS CodeDeploy

Page 52: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

Page 53: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

まとめ

• サーバーレスであっても使い慣れた環境で開発することが出来る

• サーバーレス “ならでは” をサポートするためのツールキットやフレームワークを活用すると開発生産性向上に期待できる

• テストやリリース、自動化などに関する基本的な考え方とプラクティスも他のパラダイムのときと同様

Page 54: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

Thank you!

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

鈴木哲詩

@studio3104

Page 55: サーバーレスアプリケーション開発環境€¦ · AWS Lambda AWS AppSync Amazon QuickSight Amazon Kinesis AWS Step Functions Amazon Simple Notification Service ... 画像処理

Thank you!

© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.

- Events

- Webinar

- Archive