Slide 1

Slide 1 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Serverless Testing Beyond Beginner 1 @_kensh サーバーレス をテストしよう

Slide 2

Slide 2 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Who am I? 2 • Name • Kensuke Shimokawa • Company • Amazon Web Services Japan K.K. • Role • Serverless Specialist Solutions Architect @_kensh

Slide 3

Slide 3 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Agenda 3 • Serverless のTEST戦略 • Serverless のUnit Test • Serverless のMock Test • Serverless のFake “Test” • Serverless のIntegration Test @_kensh

Slide 4

Slide 4 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 4 ServerlessのTEST戦略

Slide 5

Slide 5 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 5 CloudFormation Stack Role 今まで、ふわっと流してたけど、Testってどうしよう? Code Version Control Build Test Deploy CloudFormation

Slide 6

Slide 6 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Testing Pyramid 6

Slide 7

Slide 7 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Test を Pure に保つ 7 Handler Lambda Trigger : Event Context Resources DynamoDB S3 RDS Pure language logic functional を が も 知らなくて良い

Slide 8

Slide 8 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Testing Pyramid 8 Pure

Slide 9

Slide 9 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 9 ServerlessのUnit Test

Slide 10

Slide 10 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 10 Serverless Unit Test では、 Test を Pure に保とう。

Slide 11

Slide 11 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 具体例で考えてみよう。 11 複数注文 合計金額 Mobile Order

Slide 12

Slide 12 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. シンプルなアーキテクチャ図 12 Amazon API Gateway AWS Lambda Amazon DynamoDB Mobile client

Slide 13

Slide 13 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. シンプルなアーキテクチャ図 13 Amazon API Gateway AWS Lambda Amazon DynamoDB Mobile client を が

Slide 14

Slide 14 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. シンプルなアーキテクチャ図 14 Amazon API Gateway AWS Lambda Amazon DynamoDB Mobile client を が よく知ってますか?

Slide 15

Slide 15 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. シンプルなアーキテクチャ図 15 Amazon API Gateway AWS Lambda Amazon DynamoDB Mobile client を が よく知ってますか? Integration Test には外世界の知識が必要!

Slide 16

Slide 16 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. DynamoDB 商品価格マスタ 16 Amazon DynamoDB id name yen 22 Tea 120 24 Cola 150 27 Coffee 300

Slide 17

Slide 17 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Lambda関数実装例 17 def lambda_handler(event, context): ordered = event['multiValueQueryStringParameters']['ordered'] placed = [] for id in ordered: result = table.query( KeyConditionExpression=Key('id').eq(id) ) item = result['Items'] placed.extend(item) mapped = list(map(lambda x: x['yen'], placed)) reduced = reduce(lambda x,y: x + y, mapped) conversioned = math.ceil(reduced * rate * 100) / 100 return { 'statusCode': 200, 'body': json.dumps("{} doller".format(conversioned)) }

Slide 18

Slide 18 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Lambda関数実装例 18 def lambda_handler(event, context): ordered = event['multiValueQueryStringParameters']['ordered'] placed = [] for id in ordered: result = table.query( KeyConditionExpression=Key('id').eq(id) ) item = result['Items'] placed.extend(item) mapped = list(map(lambda x: x['yen'], placed)) reduced = reduce(lambda x,y: x + y, mapped) conversioned = math.ceil(reduced * rate * 100) / 100 return { 'statusCode': 200, 'body': json.dumps("{} doller".format(conversioned)) } を が が

Slide 19

Slide 19 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Lambda関数実装例 19 def lambda_handler(event, context): ordered = event['multiValueQueryStringParameters']['ordered'] placed = [] for id in ordered: result = table.query( KeyConditionExpression=Key('id').eq(id) ) item = result['Items'] placed.extend(item) mapped = list(map(lambda x: x['yen'], placed)) reduced = reduce(lambda x,y: x + y, mapped) conversioned = math.ceil(reduced * rate * 100) / 100 return { 'statusCode': 200, 'body': json.dumps("{} doller".format(conversioned)) } が が を

Slide 20

Slide 20 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Lambda関数実装例 20 def lambda_handler(event, context): ordered = event['multiValueQueryStringParameters']['ordered'] placed = [] for id in ordered: result = table.query( KeyConditionExpression=Key('id').eq(id) ) item = result['Items'] placed.extend(item) mapped = list(map(lambda x: x['yen'], placed)) reduced = reduce(lambda x,y: x + y, mapped) conversioned = math.ceil(reduced * rate * 100) / 100 return { 'statusCode': 200, 'body': json.dumps("{} doller".format(conversioned)) } も 合計金額

Slide 21

Slide 21 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Lambda関数実装例 21 def lambda_handler(event, context): ordered = event['multiValueQueryStringParameters']['ordered'] placed = [] for id in ordered: result = table.query( KeyConditionExpression=Key('id').eq(id) ) item = result['Items'] placed.extend(item) mapped = list(map(lambda x: x['yen'], placed)) reduced = reduce(lambda x,y: x + y, mapped) conversioned = math.ceil(reduced * rate * 100) / 100 return { 'statusCode': 200, 'body': json.dumps("{} doller".format(conversioned)) } UNIT TEST 合計金額

Slide 22

Slide 22 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Lambda関数実装 リファクタ例 22 def lambda_handler(event, context): ordered = event['multiValueQueryStringParameters']['ordered'] placed = [] for id in ordered: result = table.query( KeyConditionExpression=Key('id').eq(id) ) item = result['Items'] placed.extend(item) conversioned = calc(placed) return { 'statusCode': 200, 'body': json.dumps("{} doller".format(conversioned)) } def calc(placed): mapped = list(map(lambda x: x['yen'], placed)) reduced = reduce(lambda x,y: x + y, mapped) conversioned = math.ceil(reduced * rate * 100) / 100 return conversioned UNIT TEST 合計金額

Slide 23

Slide 23 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Lambda関数実装 Unit Test例 23 @pytest.fixture() def placed(): return [{'id': '22', 'name': 'Tea', 'yen': Decimal('120')}, {'id': '24', 'name': 'Cola', 'yen': Decimal('150')}, {'id': '27', 'name': ‘Coffee', 'yen': Decimal('300’)}] def test_calc(placed, mocker): ret = app.calc(placed) assert ret == Decimal(5.19) 合計金額 https://docs.pytest.org/

Slide 24

Slide 24 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Pure Language による Unit Testing の意義 24 • 外部の知識がなくてもテストケースが書ける • 他のAWSサービスとの結合方法に対する知識を用いない • 外部API、別のクラウド、オンプレミスとの統合に対する知識を用いない • テストが軽くなるため、開発やデリバリーを高速化できる。 • イテレーションがしやすくなる • 外部のアーキテクチャが変更された時にも、テストケースが影響を受けにくい • テストの陳腐化が防げる • テストのメンテナンスコストの軽減 • Pure Languageなので可読性があがる • AWSサービスや外部サービスの識者でなくても、テストケースから仕様をみてとれる。

Slide 25

Slide 25 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Pure Language による Unit Testing の意義 25 • 外部の知識がなくてもテストケースが書ける • 他のAWSサービスとの結合方法に対する知識を用いない • 外部API、別のクラウド、オンプレミスとの統合に対する知識を用いない • テストが軽くなるため、開発やデリバリーを高速化できる。 • イテレーションがしやすくなる • 外部のアーキテクチャが変更された時にも、テストケースが影響を受けにくい • テストの陳腐化が防げる • テストのメンテナンスコストの軽減 • Pure Languageなので可読性があがる • AWSサービスや外部サービスの識者でなくても、テストケースから仕様をみてとれる。 Serverlessはコードが小さい TDDしやすい!!

Slide 26

Slide 26 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 26 ServerlessのMock Test

Slide 27

Slide 27 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 27 でも、リファクタに労力がかけれない、、、

Slide 28

Slide 28 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 28 Serverless Unit Test では Mockを使おう。

Slide 29

Slide 29 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Test Double 29 Test Double Dummy Stub Spy Mock Fake https://martinfowler.com/bliki/TestDouble.html Test Doubleは、テスト目的で本番オブジェクトを 置き換える場合の置き換えデザインパターンを表す用語です。 さまざまな種類のdoubleがあります。

Slide 30

Slide 30 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Test Double 30 Test Double Dummy Stub Spy Mock Fake https://martinfowler.com/bliki/TestDouble.html Test Doubleは、テスト目的で本番オブジェクトを 置き換える場合の置き換えデザインパターンを表す用語です。 さまざまな種類のdoubleがあります。

Slide 31

Slide 31 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Mock の概念 31 • Mock は以下の場合に使われます。 • 実動コードを呼び出したくない場合 • 意図したコードが実行されたことを確認する 簡単な方法がない場合 例) メール送信サービスを呼び出す機能 https://blog.pragmatists.com/test-doubles-fakes-mocks-and-stubs-1a7491dfa3da

Slide 32

Slide 32 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Mocking AWS 32 https://github.com/spulec/moto

Slide 33

Slide 33 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Mocking AWS 33

Slide 34

Slide 34 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. テストケースデコレータによる自動モック化機能 34

Slide 35

Slide 35 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Mock による Unit Testing の意義 35 • 外部の知識はある程度必要だが、 • 擬似的な結合テストケースが書ける • 過度なリファクタリングに頼らず、手続きを重視したロジックを書ける • Mock利用のため、テストは軽いまま、開発やデリバリーを高速化できる。 • イテレーションはしやすい • 外部のアーキテクチャが変更された時には、テストケースが影響を受ける • テストの陳腐化を防止するため、結合AWSサービス設定を変えた場合にテストケースも変更する

Slide 36

Slide 36 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Mock による Unit Testing の意義 36 • 外部の知識はある程度必要だが、 • 擬似的な結合テストケースが書ける • 過度なリファクタリングに頼らず、手続きを重視したロジックを書ける • Mock利用のため、テストは軽いまま、開発やデリバリーを高速化できる。 • イテレーションはしやすい • 外部のアーキテクチャが変更された時には、テストケースが影響を受ける • テストの陳腐化を防止するため、結合AWSサービスを変えた場合にテストケースも変更する Mockが利用できれば、TDDしやすい!!

Slide 37

Slide 37 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Testing Pyramid 37 Pure Mock

Slide 38

Slide 38 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 38 ServerlessのFake “Test”

Slide 39

Slide 39 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Testing Pyramid 39 問題はこの層︕ Pure Mock

Slide 40

Slide 40 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Serverless は、分散アーキテクチャ 40 静的コンテンツ 動的データ 記事/試合状況 フォロー状況管理 認可 (フェデレーション) ログの保存 ETL処理 ログ収集 データ分析 クローリング 記事に対する処理 (タグ付けなど) 変更通知 画像に対する処理 (顔座標の検出) Amazon CloudWatch AWS X-Ray

Slide 41

Slide 41 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Serverless は、分散アーキテクチャ 41 静的コンテンツ 動的データ 記事/試合状況 フォロー状況管理 認可 (フェデレーション) ログの保存 ETL処理 ログ収集 データ分析 クローリング 記事に対する処理 (タグ付けなど) 変更通知 画像に対する処理 (顔座標の検出) Amazon CloudWatch AWS X-Ray ロジックが、複数サービスにまたがる。

Slide 42

Slide 42 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 42 Serverless Integration Test の戦略

Slide 43

Slide 43 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Test Double の Fake を使ってみる 43 Test Double Dummy Stub Spy Mock Fake https://martinfowler.com/bliki/TestDouble.html

Slide 44

Slide 44 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Fake の概念 44 例) 避難訓練での、避難放送 https://blog.pragmatists.com/test-doubles-fakes-mocks-and-stubs-1a7491dfa3da • Fakeとは、 • 実際に機能する実装を備えたオブジェクト • 実稼働のものとは実装が異なる • いくつかの実装上のショートカットを取り、 プロダクション実装より簡素化される

Slide 45

Slide 45 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS SAM CLI での Fake 45 1. ローカル起動用の Dummy Event データ生成 2. ローカルでLambdaを eventデータを指定して実行 SAM CLI $ sam local invoke -e event.json $ sam local generate-event \ apigateway aws-proxy \ --path datadog_report \ --method GET > event.json event.json

Slide 46

Slide 46 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS SAM CLI での Fake 46 1. ローカルでAPI Gatewayから、Lambda呼び出し実行 2. http://127.0.0.1:3000 で起動 3. ローカルブラウザ、 curl などでアクセスし実行 SAM CLI $ sam local start-api event $ curl http://127.0.0.1:3000/hello

Slide 47

Slide 47 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS が提供する、その他の Fake 47 Step Functions Local ECS Local Container Endpoints CodeBuild Local Builds CodeBuild環境をローカルで シミュレートして、BuildSpec ファイルにあるコマンドと設 定のトラブルシューティング をすぐに行えるようになります Fargate&ECSに展開 する前にアプリケー ションをローカルで テストするのに役立 ちます ローカル開発環境で実 行されている StepFunctionsを使用 してアプリケーション を開発およびローカル テストできます https://hub.docker.com/u/amazon DynamoDB Local プロビジョニング されたスループッ ト、データストレ ージ、またはデー タ転送のコストは ありません。

Slide 48

Slide 48 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 48 3rd Party Fake https://localstack.cloud/

Slide 49

Slide 49 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 49 3rd Party Fake https://localstack.cloud/ •API Gateway at http://localhost:4567 •Kinesis at http://localhost:4568 •DynamoDB at http://localhost:4569 •DynamoDB Streams at http://localhost:4570 •S3 at http://localhost:4572 •Firehose at http://localhost:4573 •Lambda at http://localhost:4574 •SNS at http://localhost:4575 •SQS at http://localhost:4576 •Redshift at http://localhost:4577 •Elasticsearch Service at http://localhost:4578 •SES at http://localhost:4579 •Route53 at http://localhost:4580 •CloudFormation at http://localhost:4581 •CloudWatch at http://localhost:4582 •SSM at http://localhost:4583 •SecretsManager at http://localhost:4584 •StepFunctions at http://localhost:4585 •CloudWatch Logs at http://localhost:4586 •EventBridge (CloudWatch Events) at http://localhost:4587 •STS at http://localhost:4592 •IAM at http://localhost:4593 •EC2 at http://localhost:4597 •KMS at http://localhost:4599

Slide 50

Slide 50 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 50 https://localstack.cloud/ 3rd Party Fake

Slide 51

Slide 51 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Fake によるテストを、どの層に含めるか? 51 Pure Mock

Slide 52

Slide 52 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Fake によるテストを、どの層に含めるか? 52 Pure Mock Fake Unit Test ?

Slide 53

Slide 53 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Fake による Unit Testing の問題意識 53 • 外部の知識が十分でないとテストケースが書けない • 他のAWSサービスとの結合方法に対する知識が必要 • Fakeモジュールに関する知識が必要 ( ie. Dockerでの起動、compose方法 ) • テストが重くなるため、開発やデリバリーが低速化する。 • イテレーションがし難くなる • 外部のアーキテクチャが変更された時にも、テストケースが容易に影響を受ける • テストの陳腐化が起り易い • テストのメンテナンスコストの増大 • Test Case維持が属人化する • AWSサービスや、Fakeの識者でないと、テストケースから仕様やアーキテクチャが判断し難い

Slide 54

Slide 54 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Fake による Unit Testing の問題意識 54 • 外部の知識が十分でないとテストケースが書けない • 他のAWSサービスとの結合方法に対する知識が必要 • Fakeモジュールに関する知識が必要 ( ie. Dockerでの起動、compose方法 ) • テストが重くなるため、開発やデリバリーが低速化する。 • イテレーションがし難くなる • 外部のアーキテクチャが変更された時にも、テストケースが容易に影響を受ける • テストの陳腐化が起り易い • テストのメンテナンスコストの増大 • Test Case維持が属人化する • AWSサービスや、Fakeの識者でないと、テストケースから仕様やアーキテクチャが判断し難い TDDし難い!! Unit Test と呼ぶには規模が大きい

Slide 55

Slide 55 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Fake によるテストを、どの層に含めるか? 55 Pure Mock Fake Integration Test ?

Slide 56

Slide 56 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Fake による Integration Testing の問題意識 56 • コストをかけてLocal Fakeを準備しても • 結局、本物のAWSサービスと動作が違う • 最新のサービス機能や新サービスが、Fakeに反映されていない • 統合サポートが不十分 • 結合で確認したい永続層のサポートが不十分 • Fake 間の Event Drivenな統合のサポートが不十分 • Test が Fail したときに判断がし辛い • 実装ロジックが悪いのか • Fakeを用いたTest Caseが悪いのか • Fake自体の実装が悪いのか • ローカル環境依存の間欠的なものなのか ( docker container 多数起動によるリソース枯渇?)

Slide 57

Slide 57 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Fake による Integration Testing の問題意識 57 • コストをかけてLocal Fakeを準備しても • 結局、本物のAWSサービスと動作が違う • 最新のサービス機能や新サービスが、Fakeに反映されていない • 統合サポートが不十分 • 結合で確認したい永続層のサポートが不十分 • Fake 間の Event Drivenな統合のサポートが不十分 • Test が Fail したときに判断がし辛い • 実装ロジックが悪いのか • Fakeを用いたTest Caseが悪いのか • Fake自体の実装が悪いのか • ローカル環境依存の間欠的なものなのか ( docker container 多数起動によるリソース枯渇?) Integration Test はAWS上でやりたい

Slide 58

Slide 58 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 58 Pure Mock Fake はCodingフェーズには便利 (補足) Fake Coding中、Fakeを常駐させ ておき、対話させるなど便利

Slide 59

Slide 59 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 59 ServerlessのIntegration Test

Slide 60

Slide 60 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 60 Serverless Integration Testing on AWS

Slide 61

Slide 61 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Serverless は使った分だけのお支払い (おさらい) 61 • リクエスト数、ならびに処理の実行時間 に応じた課金となり、実際の処理量と金 額が比例する • 事前の初期投資が不要なので、コストゼ ロからのスタートが可能

Slide 62

Slide 62 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Multi Environment 62 Environment Development Pipeline Test Production デリバリーライフサイクルに応じて環境を個別に用意する

Slide 63

Slide 63 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Multi Environment 63 デリバリーライフサイクルに応じて環境を個別に用意する Environment Development Pipeline Test Production Serverless Serviceはご利用分の従量課金 だから、環境分離に向いています

Slide 64

Slide 64 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. どう環境を分けるのか? 64 VPC Subnet Region CloudFormation Stack Account

Slide 65

Slide 65 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. どう環境を分けるのか? 65 VPC Subnet Region CloudFormation Stack Account Serverless Serviceは、VPCや Subnetに依存していないものも 多いため、難しい 商用と同じ環境でStackの Deploy/Rollbackを、実行 するのは危険 Account単位のサービス 上限のケアや、Region 単位での、新サービスの 対応状況の違いがある 可能であれば、Multi Accout のデリバリー パイプラインを構築

Slide 66

Slide 66 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Environment Development Pipeline Test Production Multi Account 66 デリバリーライフサイクルに応じて AWS Account を個別に用意する Account Account Account Account

Slide 67

Slide 67 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS Organizations を利用すると、Account管理が便利に 67 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

Slide 68

Slide 68 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Cross Account Delivery Pipeline 68 Developers AWS Cloud AWS Cloud AWS Cloud AWS Cloud AWS CodeCommit AWS CodeBuild AWS CodePipeline CloudFormation CloudFormation Stack CloudFormation CloudFormation Stack Test Account Production Account Pipeline Account Development Account Cross Accountにまた がる権限が必要 https://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/

Slide 69

Slide 69 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Cross Account Delivery Pipeline 69 AWS Cloud AWS Cloud AWS Cloud AWS CodeCommit AWS CodeBuild AWS CodePipeline CloudFormation CloudFormation Stack Test Account Pipeline Account Development Account IAM Role Bucket IAM Role IAM Role https://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/ Developers

Slide 70

Slide 70 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Cross Account Delivery Pipeline 70 AWS Cloud AWS Cloud AWS Cloud AWS CodeCommit AWS CodeBuild AWS CodePipeline CloudFormation CloudFormation Stack Test Account Pipeline Account Development Account IAM Role Bucket IAM Role Code Checkout IAM Role Assum e Role Put Code CodeCommitから CodeをCheckout https://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/ Developers

Slide 71

Slide 71 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Developers Cross Account Delivery Pipeline 71 AWS Cloud AWS Cloud AWS Cloud AWS CodeCommit AWS CodeBuild AWS CodePipeline CloudFormation CloudFormation Stack Test Account Pipeline Account Development Account IAM Role Bucket IAM Role Code Checkout IAM Role Assum e Role Put Code Trigger Sourceが checkout 完了したら、 CodeBuildを実⾏ https://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/

Slide 72

Slide 72 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Cross Account Delivery Pipeline 72 AWS Cloud AWS Cloud AWS Cloud AWS CodeCommit AWS CodeBuild AWS CodePipeline CloudFormation CloudFormation Stack Test Account Pipeline Account Development Account IAM Role Bucket IAM Role Code Checkout IAM Role Assum e Role Put Code Trigger Put Package Codeをビルドし、 PackageをS3にPutする https://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/ Developers

Slide 73

Slide 73 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Cross Account Delivery Pipeline 73 AWS Cloud AWS Cloud AWS Cloud AWS CodeCommit AWS CodeBuild AWS CodePipeline CloudFormation CloudFormation Stack Test Account Pipeline Account Development Account IAM Role Bucket IAM Role Code Checkout IAM Role Assum e Role Put Code Trigger Put Package Assum e Role Pass the Role CloudFormation 実⾏ Execute https://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/ Developers

Slide 74

Slide 74 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Cross Account Delivery Pipeline 74 AWS Cloud AWS Cloud AWS Cloud AWS CodeCommit AWS CodeBuild AWS CodePipeline CloudFormation CloudFormation Stack Test Account Pipeline Account Development Account IAM Role Bucket IAM Role Code Checkout IAM Role Assum e Role Put Code Trigger Put Package Assum e Role Pass the Role Execute https://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/ Developers

Slide 75

Slide 75 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Cross Account Delivery Pipeline 75 AWS Cloud AWS Cloud AWS Cloud AWS CodeCommit AWS CodeBuild AWS CodePipeline CloudFormation CloudFormation Stack Test Account Pipeline Account Development Account IAM Role Bucket IAM Role Code Checkout IAM Role Assum e Role Put Code Trigger Put Package Assum e Role Pass the Role Execute Cross Account でデリバリー完了! https://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/ Developers

Slide 76

Slide 76 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 実際にIntegration Test してみよう 76 AWS Cloud Test Account https://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/ Developers AWS Cloud Development Account Integration Test 対象 サービス

Slide 77

Slide 77 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 実際にIntegration Test してみよう 77 AWS Cloud Test Account https://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/ Developers AWS Cloud Development Account Container Amazon Elastic Container Service テストシナリオを 配備しておく テスト実⾏⽤の リソースを確保

Slide 78

Slide 78 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 実際にIntegration Test してみよう 78 AWS Cloud Test Account https://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/ Developers AWS Cloud Development Account Container Amazon Elastic Container Service テストシナリオを 実⾏

Slide 79

Slide 79 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 実際にIntegration Test してみよう 79 AWS Cloud Test Account https://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/ Developers AWS Cloud Development Account Container Amazon Elastic Container Service テストシナリオを 実⾏ Cross Account でIntegration Test 完了!

Slide 80

Slide 80 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Test のためのリソース維持やコストが気になる? 80 AWS Cloud Test Account https://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/ Developers AWS Cloud Development Account Container Amazon Elastic Container Service テスト実⾏⽤の リソースを確保

Slide 81

Slide 81 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Test のためのリソース維持やコストが気になる? 81 AWS Cloud Test Account https://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/ Developers AWS Cloud Development Account Container Amazon Elastic Container Service テスト実⾏⽤の リソースを確保 Test 用のリソースも Serverlessで作るのは?

Slide 82

Slide 82 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Test のためのリソース維持やコストが気になる? 82 AWS Cloud Test Account https://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/ Developers AWS Cloud Development Account Container Amazon Elastic Container Service

Slide 83

Slide 83 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Test のためのリソース維持やコストが気になる? 83 AWS Cloud Test Account https://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/ Developers AWS Cloud Development Account funtion AWS Lambda テスト実⾏⽤の リソースを Serverless化

Slide 84

Slide 84 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 84 https://github.com/Nordstrom/serverless-artillery 3rd Party

Slide 85

Slide 85 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 85 https://github.com/Nordstrom/serverless-artillery 3rd Party

Slide 86

Slide 86 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Test のためのリソース維持やコストが気になる? 86 AWS Cloud Test Account https://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/ Developers AWS Cloud Development Account funtion AWS Lambda Serverless-artillery テストシナリオを 配備しておく

Slide 87

Slide 87 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Test のためのリソース維持やコストが気になる? 87 AWS Cloud Test Account https://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/ Developers AWS Cloud Development Account funtion AWS Lambda Serverless-artillery テストシナリオを 実⾏

Slide 88

Slide 88 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Test のためのリソース維持やコストが気になる? 88 AWS Cloud Test Account https://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/ Developers AWS Cloud Development Account funtion AWS Lambda Serverless-artillery テストシナリオを 実⾏ Serverless による Serverless の試験完了!

Slide 89

Slide 89 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. Cross Account Delivery Pipeline with Testing 89 Developers AWS Cloud AWS Cloud AWS Cloud AWS Cloud AWS CodeCommit AWS CodeBuild AWS CodePipeline CloudFormation CloudFormation Stack CloudFormation Stack Test Account Production Account Pipeline Account Development Account テスト実⾏⽤ Test Requests Test Script

Slide 90

Slide 90 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 90 まとめ

Slide 91

Slide 91 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. まとめ 91 • 今回は、サーバーレス のテスト方法の一部をご紹介しました。 • 環境やプロダクトやビジネスに応じて、また、異なった戦略があるかもしれません。 • ワークロードに適合する戦略を立てテストしましょう。 • デプロイするだけで、実行されなければ課金されないという、サーバーレス の特徴を活か して、Multi Accountでテスト環境を整備するメリットもご紹介いたしました。 • テスト効率を上げることによって、デリバリーパイプラインを高速化できます。 • よりビジネスに貢献する開発に、その時間を当てることができます。 • テストを自動化して、属人化したテスト手法を見直してみましょう。

Slide 92

Slide 92 text

© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 92 Thank you ! @_kensh