Upgrade to Pro — share decks privately, control downloads, hide ads and more …

2021年版、サーバーレスのテスト手法を考える / Serverless Testing 2021

kensh
September 28, 2021

2021年版、サーバーレスのテスト手法を考える / Serverless Testing 2021

動画はこちら
https://twitter.com/_kensh/status/1468951162053607424?s=20

サーバーレスはサクっと作れるのは良いけれどテストやデバッグが大変だって思うことはないでしょうか? 難しさの理由としてプログラミングコードのテストだけでなく、サービスを統合した結合部分の設定、分散するコンポーネントの関係性、同期だけでなく非同期的に動作するイベントドリブンなコンポーネントのテストの方法論が浸透していない事にあるのではないでしょうか。このセッションでは実践的なサーバーレスのテスト手法やテストにおける注意点やチップスを含めてお届けします。

kensh

September 28, 2021
Tweet

More Decks by kensh

Other Decks in Programming

Transcript

  1. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 2021年版 サーバーレスのテスト⼿法を考える Kensuke Shimokawa Amazon Web Services Japan Snr. Serverless Specialist A - 4
  2. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Kensuke Shimokawa Amazon Web Services Japan Snr. Serverless Specialist
  3. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. • サービスを提供するということ • テスト・ピラミッド • サーバーレスアーキテクチャ の特性 • リモートデプロイ、実⾏、動作確認 • 外部リソースを含むテスト • 広範なスタックで構成されたビジネスロジック • ⾮同期の副作⽤を伴うテスト • 開発者向けクラウド環境 Agenda
  4. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. サービスを提供するということ
  5. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. サービスを提供するということ 新規コードによる フィードバックを⾼速化 変更影響の凝集度 迅速、安全な リリース 変更容易性 既存影響の把握 デグレ検知 セキュリティ, 可⽤性, コ スト影響、性能劣化の検出 と把握 CI / CD デプロイと ロールバックの⾃動化
  6. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. サービスを提供するということ 新規コードによる フィードバックを⾼速化 変更影響の凝集度 迅速、安全な リリース 変更容易性 既存影響の把握 デグレ検知 セキュリティ, 可⽤性, コ スト影響、性能劣化の検出 と把握 CI / CD デプロイと ロールバックの⾃動化
  7. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. テスト・ピラミッド
  8. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. テスト・ピラミッド ⾼速な Unit Test を最⼤化して、低速な E2E を最⼩化する マニュアル(⼿動)でのテストは排除する 低速 記述困難 失敗原因の解析困難 テスト範囲 広範囲 テスト範囲 局所 ⾼速 記述容易 失敗原因の特定容易 Unit Integration E2E Service Mike Cohn (2004) https://www.mountaingoatsoftware.com/blog/the-forgotten-layer-of-the-test-automation-pyramid
  9. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. ⾃動テストのスコープ Micro Service Micro Service Micro Service Micro Service User Interface Micro Service
  10. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. ⾃動テストのスコープ Micro Service Micro Service Micro Service Micro Service User Interface Micro Service E2E
  11. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. ⾃動テストのスコープ Micro Service Micro Service Micro Service Micro Service User Interface Micro Service func() func() func() func() func() func() func() func() E2E
  12. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. ⾃動テストのスコープ Micro Service Micro Service Micro Service Micro Service User Interface Micro Service func() func() func() func() func() func() func() func() E2E Unit Integration Service Unit
  13. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. どんな⾃動テストを作るべきか 実⾏について 実装について 理解について 運⽤について ⾼速 決定的 分離 失敗原因把握 チームメンバーの理解容易 シンプル 拡張性 間⽋的な失敗とならない サービス進化によって陳腐化しない Unit Test
  14. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. テスト・ピラミッド (再掲) ⾼速な Unit Test を最⼤化して、低速な E2E を最⼩化する マニュアル(⼿動)でのテストは排除する 低速 記述困難 失敗原因の解析困難 テスト範囲 広範囲 テスト範囲 局所 ⾼速 記述容易 失敗原因の特定容易 Unit Integration E2E Service Mike Cohn (2004) https://www.mountaingoatsoftware.com/blog/the-forgotten-layer-of-the-test-automation-pyramid
  15. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. サーバーレスアーキテクチャの特性
  16. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. サービスの迅速な顧客提供 スケーラブル, ⾼信頼, セキュア, 低い TCO サーバーレスの効果 分散 アーキテク チャ 機能性 マネージド サービス コードを、状態, ルーティング, オーケストレーション, ポーリング から分離 ⽔平⽅向にスケーリング フォールトトレラント 最⼩権限の実⾏環境 アプリケーションを迅速に開発 ビジネス価値に焦点を当てる インフラ管理責任を AWS にオフロード 利⽤した分のみのお⽀払い イベント駆動型アーキテクチャで サービスを疎結合に分離 並列に新機能をデリバリー
  17. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. サーバーレスのテストにおけるチャレンジ リモートデプロイ、実⾏、動作確認 外部リソースを含むテスト 広範なスタックで構成されたビジネスロジック ? ⾮同期の副作⽤を伴うテスト AWS Step Functions 分散 アーキテク チャ 機能性 マネージド サービス
  18. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. リモートデプロイ、実⾏、動作確認 Challenge 1
  19. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. デプロイやランタイム環境の違い ローカル環境でデプロイ、実⾏、デバッグ リモート環境にデプロイ、実⾏、デバッグ Local runtime environment Remote runtime environment サーバーレス アプリケーション これまでのアプリケーション
  20. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 典型的なサーバーレスアーキテクチャ Amazon SQS AWS Lambda Amazon DynamoDB Amazon API Gateway AWS Lambda
  21. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. システム全体をローカルエミュレーション local machine Amazon SQS AWS Lambda Amazon DynamoDB Amazon API Gateway AWS Lambda デプロイせず E2E で変更をオフラインテスト ⾮現実的なフィードバック(不完全なエミュレーション) インフラ設定を複製/グルーコードを書く https://localstack.cloud https://hub.docker.com/r/amazon/dynamodb-local
  22. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Lambda と同期イベントソースをエミュレート local machine Amazon SQS AWS Lambda Amazon DynamoDB Amazon API Gateway AWS Lambda poll & forward DynamoDB Streams synthetic event $> sam local start-api $> sam local start-lambda https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-command-reference.html
  23. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Lambda と同期イベントソースをエミュレート local machine Amazon SQS AWS Lambda Amazon DynamoDB Amazon API Gateway AWS Lambda poll & forward DynamoDB Streams synthetic event デプロイせずに多くの変更をテストする ローカルブレークポイントのデバッグ ⾮同期/ストリームイベントソースポーリング など まだクラウドで確認するポイントが残る
  24. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Lambda のエミュレートと、イベント転送 local machine Amazon SQS Proxy Lambda Function Code Amazon DynamoDB Amazon API Gateway Proxy Lambda Function Code Real Lambda Function Code Real Lambda Function Code 実際のイベントで関数コードを反復開発する 実際の実⾏の役割と権限 専⽤ツールの為のインフラストラクチャをデプロイ 幅広くテストできるが、不要リソースが⽣じる https://docs.serverless-stack.com/live-lambda-development#sst-start
  25. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. エミュレーションなし local machine Amazon SQS Amazon DynamoDB handler() handler() Amazon SQS Amazon DynamoDB API Gateway synthetic event DynamoDB Streams synthetic event 信頼できるフィードバック( IAM 権限を除く) 狭い範囲のテスト 実際のイベントソースと権限は、関数をデプロイし、 別途確認
  26. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. ローカルテストのアプローチ エミュレーション 度合い システム全体 Lambda と 同期イベントソース Lambda と イベント転送 なし デプロイなし テスト可能範囲 システム全体 API Gateway, AppSync, Step Functions, Lambda Lambda 関数コード Lambda 関数コード フィードバック スピード 🚀 🏃 🏃 🚶 クラウド再現度 最低 低い
  27. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. ローカルテストのアプローチ エミュレーション 度合い システム全体 Lambda と 同期イベントソース Lambda と イベント転送 なし デプロイなし テスト可能範囲 システム全体 API Gateway, AppSync, Step Functions, Lambda Lambda 関数コード Lambda 関数コード フィードバック スピード 🚀 🏃 🏃 🚶 クラウド再現度 最低 低い 多くのフィードバックは Unit Test から得られる (Test Pyramid) インフラの変更はコードの変 更ほど頻繁に起こらない 正確性を犠牲にすると、 結果的にテストスピードが 落ちる 🚀 コード主体の テストであれば ここを選択
  28. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 外部リソースを含むテスト Challenge 2
  29. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 外部リソースアクセスパターンの違い Readings Table Parser Function サーバーレス アプリケーション Parse File Save Readings Run Analysis Save File Save Result これまでのアプリケーション Data File Bucket Enqueue Function Analysis Queue Results Table Notify Function AWS AppSync { x: 5, y: 12 } { x: 5, y: 12 } 多くの外部サービスをイベントが伝搬 外部サービスとの結合部分でテストが必要 少ない外部リソースに多くアクセス 外部リソースターゲットのテストは少なめ Analysis Function
  30. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Lambda 関数をトリガーする AWS サービス Parser Function S3 Bucket Lambda へのイベント通知設定 DynamoDB Table Notify Function イベントソースマッピング設定 イベントをパースし処理 Put Object Put Item
  31. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Lambda 関数から AWS サービスにアクセス DynamoDB Table Parser Function AWS AppSync Parser Function Synthetic Event Synthetic Event
  32. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 外部リソースを含むテストの最⼩化 local machine handler() ビジネスロジックは 3つの仕様から構成 3ケースのDynamoDBを含むテスト test() { orderId: 3af1e5 isPremiumCustomer: true totalCents: 4500 details: { ... } } 1) プレミアム契約では、 2) $50以上の購入で、 3) $10 減額 ビジネスロジック 外部リソース DynamoDB テーブルに 注文情報登録 act() assert()
  33. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 外部リソースを含むテストの最⼩化 local machine handler() OrderRepository 1) プレミアム契約では、 2) $50以上の購入で、 3) $10 減額 ビジネスロジック 外部リソース DynamoDB テーブルに 注文情報登録 分離された3ケース test() test() 外部アクセスの テストを1つに act() assert() act() assert()
  34. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 外部との Integration Test local machine handler() OrderRepository 外部リソース DynamoDB テーブルに 注文情報登録 test() 外部アクセスの テストを1つに act() assert() 焦点を絞ったテストの結果確認/拡張が容易 迅速で正確なフィードバック IAM権限はテスト対象外
  35. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 関数ハンドラーの Unit Test local machine handler() OrderRepository 1) プレミアム契約では、 2) $50以上の購入で、 3) $10 減額 ビジネスロジック 分離された 3ケース test() act() assert() 記述が簡単で実⾏が速い テスト失敗は診断が容易 mock()
  36. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. アーキテクチャの進化 Amazon DynamoDB Amazon API Gateway 関数の分割 関数の統合 Amazon DynamoDB イベントソース の変更 AWS AppSync Amazon DynamoDB Amazon API Gateway AWS Lambda AWS Lambda AWS Lambda AWS Lambda
  37. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 関数ハンドラーの Unit Test handler() OrderRepository local machine test() 1) プレミアム契約では、 2) $50以上の購入で、 3) $10 減額 ビジネスロジック act() assert() ロジックとイベント ソースが密に結合 記述が簡単で実⾏が速いテスト 障害の診断が容易 テストはアーキテクチャの進化に対し脆弱
  38. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. ビジネスロジックの Unit Test OrderService handler() OrderRepository biz_logic_test() ロジックとイベント ソースは分離 1) プレミアム契約では、 2) $50以上の購入で、 3) $10 減額 ビジネスロジック Handler イベントをビジネスロジック にマッピング act() assert() アーキテクチャ進化は関⼼事の外 ビジネスロジックとテストはプラットフォーム⾮依存 ハンドラー⾃体のテストにはデプロイが必要
  39. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. ビジネスロジックの分離 OrderService handler() 1) プレミアム契約では、 2) $50以上の購入で、 3) $10 減額 ビジネスロジック Handler イベントをビジネスロジック にマッピング OrderRepository 外部リソース DynamoDB テーブルに 注文情報登録
  40. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. ヘキサゴナル アーキテクチャ Adapter 特定の外部システムの ポートインターフェイス を実装 外部とドメインの概念間の マップ 「腐敗防⽌層」 DDD Domain Core どのように外世界 とやり取りするか は関⼼の範囲外 Port 外部の関⼼を隠すコード インターフェース ドメインと 外界との相互作⽤を定義 テストでの呼び出し、または モックする⼊⼝と出⼝の ポイントを提供 Alistair Cockburn (2005)
  41. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. ヘキサゴナル アーキテクチャ OrderService handler() 1) プレミアム契約では、 2) $50以上の購入で、 3) $10 減額 ビジネスロジック Handler イベントをビジネスロジック にマッピング OrderRepository 外部リソース DynamoDB テーブルに 注文情報登録 Domain Core Port: saveOrder() Port: processOrder() Adapter Adapter
  42. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 広範なスタックで構成された ビジネスロジック Challenge 3
  43. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. ビジネスロジックの配置 ReserveFlight Function CreateBooking Function ReserveHotel Function BookTrip Workflow 広範なスタックで構成された ビジネスロジック POST / HTTP/1.1 StartExecution 分散されたロジック ⼩さなスタックで Unit Test 完結 travelAgent.bookTrip() reserveFlight() reserveHotel() createBooking() TravelAgent::bookTrip() ローカルに配置されるロジック サーバーレス アプリケーション AWS Step Functions State Machine これまでのアプリケーション Class Method 入力バリデーション + データ変換 + ビジネスルール
  44. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 広範なテストのために必要な変更 Business logic handler() Order Repository Business logic handler() Order Backlog test() assert() act() assert() Unit Tests Integration Tests Permissions untested Unit Tests Integration Tests Permissions untested Deploy to test Deploy to test
  45. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 広範に及ぶテスト量を⼩さく保つ 1つのユースケースに対して 1つの E2E テストを作成 test() assert() act() assert() Amazon SNS Amazon API Gateway AWS Lambda Amazon SQS
  46. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 広範に及ぶテスト量を⼩さく保つ 1つのユースケースに対して 1つの E2E テストを作成 1つのイベントごとに 1つのテストアサートを作成 テストケースを追加するか 既存のケースを拡張するか Unit Test がパスした後に 広範なテストケースを実⾏ test() assert() act() assert() Amazon SNS Amazon API Gateway AWS Lambda Amazon SQS Amazon SQS assert()
  47. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. ⾮同期の副作⽤を伴うテスト Challenge 4
  48. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 同期・⾮同期の応答性の違い ⾮同期 マイクロサービス 同期的に得られる応答は、202(Accepted) など 同期的にレスポンス結果を確認可能 イベント駆動、結果整合 同期 マイクロサービス リクエスト/レスポンス 、強い整合性 Application Logic Web Server ? ? Amazon API Gateway AWS Lambda AWS Lambda Amazon EventBridge Amazon DynamoDB
  49. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. ⾮同期の副作⽤をテスト Business logic handler() Order Repository Business logic handler() Order Backlog test() assert() act() assert() Unit Tests Integration Tests Permissions untested Unit Tests Integration Tests Permissions untested 広範なテスト 同期 テスト 同期 テスト 狭い ⾮同期 テスト ⾮同期副作⽤
  50. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 副作⽤を検出する poll() test() Amazon SQS Test Amazon API Gateway Test AWS AppSync Amazon SNS Amazon EventBridge Test Queue poll() Amazon S3 Test Queue poll() 1 get() 2 create_subscription() 1 connect() 2 listen() 3 Amazon SQS connect() 1 listen() 2
  51. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. メッセージは テスト横断的に 保存される ⾮同期テスト⽤の共通リソース OrderBacklog test_1() test_2() テスト間の相互作⽤ キューのパージに は60s程度必要 userId: b2f6 userId: c5a1 poll() act() Unique ID を⽤意して、テスト実⾏ と副作⽤に関連づける
  52. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. ⾮同期テスト⽤の共通リソース OrderBacklog test_1() test_2() メッセージは テスト横断的に 保存される テスト間の相互作⽤ キューのパージに は60s程度必要 userId: b2f6 userId: c5a1 act() Unique ID を⽤意して、テスト実⾏ と副作⽤に関連づける poll() 専⽤のテストキューの準備 MessageRetentionPeriod = 60 delete_message()
  53. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. ⾮同期テスト⽤の共通リソース OrderBacklog test_1() test_2() メッセージは テスト横断的に 保存される テスト間の相互作⽤ キューのパージに は60s程度必要 userId: b2f6 userId: c5a1 Unique ID を⽤意して、テスト実⾏ と副作⽤に関連づける poll() act() 専⽤のテストキューの準備 MessageRetentionPeriod = 60 VisibilityTimeout = 0 No RedrivePolicy / DLQ delete_message()
  54. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 開発者向けのクラウド環境
  55. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 本番環境の分離 Staging Stack Production Account Production Stack Test Stack Non-Production Account Development Stack Infrastructure Template Template Parameters environment: dev backups: false logLevel: debug Template Parameters environment: test backups: false logLevel: warn Template Parameters environment: staging backups: false logLevel: warn Template Parameters environment: prod backups: true logLevel: info Infrastructure as code
  56. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. ステージごとの分離 Production Account Production Stack Infrastructure Template Template Parameters environment: dev backups: false logLevel: debug Template Parameters environment: test backups: false logLevel: warn Template Parameters environment: staging backups: false logLevel: warn Template Parameters environment: prod backups: true logLevel: info Infrastructure as code Staging Account Staging Stack Test Account Test Stack Development Account Development Stack
  57. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 複数の開発者が単⼀の開発環境スタックを共有 Amazon Route 53 Amazon API Gateway AWS Lambda Amazon DynamoDB Development Stack Parameter Store Stack Development Account
  58. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 開発者ごとにスタックを割り当て Amazon Route 53 Amazon API Gateway AWS Lambda Amazon DynamoDB Amazon Route 53 Amazon API Gateway AWS Lambda Amazon DynamoDB Amazon Route 53 Amazon API Gateway AWS Lambda Amazon DynamoDB Amazon Route 53 Amazon API Gateway AWS Lambda Amazon DynamoDB Alice’s Stack Parameter Store Stack Bob’s Stack Parameter Store Stack Pramod’s Stack Parameter Store Stack Development Account 接頭辞、⾃動⽣成リソ ース名で競合を回避 Jane’s Stack Parameter Store Stack 環境設定からテスト URLやARNを取得
  59. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 開発者ごとにアカウントを割り当て Amazon Route 53 Amazon API Gateway AWS Lambda Amazon DynamoDB Amazon Route 53 Amazon API Gateway AWS Lambda Amazon DynamoDB Amazon Route 53 Amazon API Gateway AWS Lambda Amazon DynamoDB Amazon Route 53 Amazon API Gateway AWS Lambda Amazon DynamoDB Alice’s Stack Parameter Store Stack Bob’s Stack Parameter Store Stack Pramod’s Stack Parameter Store Stack Jane’s Stack Parameter Store Stack Alice’s Account Jane’s Account Pramod’s Account Bob’s Account Delegated DNS zone e.g. jane.domain.com
  60. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. AWS Organizations で Account 管理 Organization Organization root OU AWS accounts Admin (master) AWS account AWS accounts AWS accounts OU OU OU OU https://www.slideshare.net/AmazonWebServicesJapan/20180214-aws-blackbeltorganizations
  61. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 開発スタックを最新に維持したい Source Control Application Template Foundation Template コードのpullの度に 最新テンプレートを適用 AWS CloudFormation StackSets Orchestration Account Development Account Alice’s Foundation Stack Amazon VPC Amazon Cognito 激しい変化 ゆっくりな変化 Alice’s Application Stack Amazon API Gateway AWS Lambda
  62. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 開発スタックを最新に維持したい Source Control Application Template Foundation Template コードのpullの度に 最新テンプレートを適用 AWS CloudFormation StackSets Orchestration Account Alice’s Application Stack Development Account Alice’s Pipeline Stack Alice’s Foundation Stack Amazon VPC Amazon Cognito AWS CodePipeline 激しい変化 ゆっくりな変化 Amazon API Gateway AWS Lambda 設定のドリフト?
  63. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. 開発スタックを最新に維持したい Source Control Application Template Foundation Template コードのpullの度に 最新テンプレートを適用 AWS CloudFormation StackSets Orchestration Account Alice’s Application Stack Development Account Alice’s Pipeline Stack Alice’s Foundation Stack Amazon VPC Amazon Cognito AWS CodePipeline 激しい変化 ゆっくりな変化 Amazon API Gateway AWS Lambda 毎日新規作成
  64. © 2021, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. まとめ • 結果確認が容易な高速で信頼性の高いテス トのために Unit Test を多くする • ローカルエミュレーションは不完全で信頼 性が低く、継続的なメンテナンスが必要 • サービスエミュレーションなしでローカル でテストできるものを最大化する • ビジネスロジックを外部リソースとの対話 コードから分離することにより、外部リ ソースとのテストを最小限に抑える • ヘキサゴナル アーキテクチャを使用して 形式化する • 広範なスタックテストを最小限に抑える • ユースケースごとに1回のE2Eテストに留 める(ビジネスロジックはUnit Testで) • 広範な非同期テストよりも、範囲の狭い 非同期テストを優先し大部分は同期にテ ストする • SQSを使用して非同期サービスの副作用 をキャプチャして確認 (上級者向け) • 開発者ごとにクラウド環境を割り当て、 Infrastructure-as-Codeを使用して、再作成を 容易に保つ Unit Integration E2E Service Domain Core
  65. Thank you! © 2021, Amazon Web Services, Inc. or its

    affiliates. All rights reserved. Kensuke Shimokawa Amazon Web Services Japan Snr. Serverless Specialist
  66. Please complete the session survey © 2021, Amazon Web Services,

    Inc. or its affiliates. All rights reserved.