サーバーレス のテスト手法について、これまでのアプリの開発と何が違うのでしょうか? 初心者の多くがブラウザから確認するなどマニュアルの手法で動作確認や検証を行なっています。サーバーレス の特徴を掴みながら、どのようにテストしたらよいかを学べるコンテンツになります。
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Serverless TestingBeyond Beginner1@_kenshサーバーレス をテストしよう
View Slide
© 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
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Agenda3• Serverless のTEST戦略• Serverless のUnit Test• Serverless のMock Test• Serverless のFake “Test”• Serverless のIntegration Test@_kensh
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 4ServerlessのTEST戦略
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 5CloudFormationStackRole今まで、ふわっと流してたけど、Testってどうしよう?CodeVersionControlBuild Test DeployCloudFormation
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Testing Pyramid6
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Test を Pure に保つ7HandlerLambdaTrigger : EventContextResourcesDynamoDBS3RDSPure languagelogicfunctionalを が も知らなくて良い
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Testing Pyramid8Pure
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 9ServerlessのUnit Test
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 10Serverless Unit Test では、Test を Pure に保とう。
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.具体例で考えてみよう。11複数注文合計金額Mobile Order
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.シンプルなアーキテクチャ図12AmazonAPI GatewayAWSLambdaAmazonDynamoDBMobileclient
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.シンプルなアーキテクチャ図13AmazonAPI GatewayAWSLambdaAmazonDynamoDBMobileclientを が
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.シンプルなアーキテクチャ図14AmazonAPI GatewayAWSLambdaAmazonDynamoDBMobileclientを がよく知ってますか?
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.シンプルなアーキテクチャ図15AmazonAPI GatewayAWSLambdaAmazonDynamoDBMobileclientを がよく知ってますか?Integration Test には外世界の知識が必要!
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.DynamoDB 商品価格マスタ16Amazon DynamoDBid name yen22 Tea 12024 Cola 15027 Coffee 300
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Lambda関数実装例17def 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) / 100return {'statusCode': 200, 'body': json.dumps("{} doller".format(conversioned))}
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Lambda関数実装例18def 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) / 100return {'statusCode': 200, 'body': json.dumps("{} doller".format(conversioned))}をがが
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Lambda関数実装例19def 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) / 100return {'statusCode': 200, 'body': json.dumps("{} doller".format(conversioned))}ががを
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Lambda関数実装例20def 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) / 100return {'statusCode': 200, 'body': json.dumps("{} doller".format(conversioned))}も合計金額
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Lambda関数実装例21def 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) / 100return {'statusCode': 200, 'body': json.dumps("{} doller".format(conversioned))}UNIT TEST合計金額
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Lambda関数実装 リファクタ例22def 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) / 100return conversionedUNIT TEST合計金額
© 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/
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Pure Language による Unit Testing の意義24• 外部の知識がなくてもテストケースが書ける• 他のAWSサービスとの結合方法に対する知識を用いない• 外部API、別のクラウド、オンプレミスとの統合に対する知識を用いない• テストが軽くなるため、開発やデリバリーを高速化できる。• イテレーションがしやすくなる• 外部のアーキテクチャが変更された時にも、テストケースが影響を受けにくい• テストの陳腐化が防げる• テストのメンテナンスコストの軽減• Pure Languageなので可読性があがる• AWSサービスや外部サービスの識者でなくても、テストケースから仕様をみてとれる。
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Pure Language による Unit Testing の意義25• 外部の知識がなくてもテストケースが書ける• 他のAWSサービスとの結合方法に対する知識を用いない• 外部API、別のクラウド、オンプレミスとの統合に対する知識を用いない• テストが軽くなるため、開発やデリバリーを高速化できる。• イテレーションがしやすくなる• 外部のアーキテクチャが変更された時にも、テストケースが影響を受けにくい• テストの陳腐化が防げる• テストのメンテナンスコストの軽減• Pure Languageなので可読性があがる• AWSサービスや外部サービスの識者でなくても、テストケースから仕様をみてとれる。Serverlessはコードが小さいTDDしやすい!!
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 26ServerlessのMock Test
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 27でも、リファクタに労力がかけれない、、、
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 28Serverless Unit Test では Mockを使おう。
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Test Double29TestDoubleDummy Stub Spy Mock Fakehttps://martinfowler.com/bliki/TestDouble.htmlTest Doubleは、テスト目的で本番オブジェクトを置き換える場合の置き換えデザインパターンを表す用語です。さまざまな種類のdoubleがあります。
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Test Double30TestDoubleDummy Stub Spy Mock Fakehttps://martinfowler.com/bliki/TestDouble.htmlTest Doubleは、テスト目的で本番オブジェクトを置き換える場合の置き換えデザインパターンを表す用語です。さまざまな種類のdoubleがあります。
© 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
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Mocking AWS32https://github.com/spulec/moto
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Mocking AWS33
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.テストケースデコレータによる自動モック化機能34
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Mock による Unit Testing の意義35• 外部の知識はある程度必要だが、• 擬似的な結合テストケースが書ける• 過度なリファクタリングに頼らず、手続きを重視したロジックを書ける• Mock利用のため、テストは軽いまま、開発やデリバリーを高速化できる。• イテレーションはしやすい• 外部のアーキテクチャが変更された時には、テストケースが影響を受ける• テストの陳腐化を防止するため、結合AWSサービス設定を変えた場合にテストケースも変更する
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Mock による Unit Testing の意義36• 外部の知識はある程度必要だが、• 擬似的な結合テストケースが書ける• 過度なリファクタリングに頼らず、手続きを重視したロジックを書ける• Mock利用のため、テストは軽いまま、開発やデリバリーを高速化できる。• イテレーションはしやすい• 外部のアーキテクチャが変更された時には、テストケースが影響を受ける• テストの陳腐化を防止するため、結合AWSサービスを変えた場合にテストケースも変更するMockが利用できれば、TDDしやすい!!
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Testing Pyramid37PureMock
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 38ServerlessのFake “Test”
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Testing Pyramid39問題はこの層︕PureMock
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Serverless は、分散アーキテクチャ40静的コンテンツ動的データ記事/試合状況フォロー状況管理認可(フェデレーション)ログの保存ETL処理ログ収集 データ分析クローリング記事に対する処理(タグ付けなど)変更通知画像に対する処理(顔座標の検出)AmazonCloudWatchAWS X-Ray
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Serverless は、分散アーキテクチャ41静的コンテンツ動的データ記事/試合状況フォロー状況管理認可(フェデレーション)ログの保存ETL処理ログ収集 データ分析クローリング記事に対する処理(タグ付けなど)変更通知画像に対する処理(顔座標の検出)AmazonCloudWatchAWS X-Rayロジックが、複数サービスにまたがる。
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 42Serverless Integration Test の戦略
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Test Double の Fake を使ってみる43TestDoubleDummy Stub Spy Mock Fakehttps://martinfowler.com/bliki/TestDouble.html
© 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とは、• 実際に機能する実装を備えたオブジェクト• 実稼働のものとは実装が異なる• いくつかの実装上のショートカットを取り、プロダクション実装より簡素化される
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.AWS SAM CLI での Fake451. ローカル起動用の 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.jsonevent.json
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.AWS SAM CLI での Fake461. ローカルでAPI Gatewayから、Lambda呼び出し実行2. http://127.0.0.1:3000 で起動3. ローカルブラウザ、 curl などでアクセスし実行SAM CLI$ sam local start-apievent$ curl http://127.0.0.1:3000/hello
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.AWS が提供する、その他の Fake47Step Functions Local ECS Local ContainerEndpointsCodeBuild Local BuildsCodeBuild環境をローカルでシミュレートして、BuildSpecファイルにあるコマンドと設定のトラブルシューティングをすぐに行えるようになりますFargate&ECSに展開する前にアプリケーションをローカルでテストするのに役立ちますローカル開発環境で実行されているStepFunctionsを使用してアプリケーションを開発およびローカルテストできますhttps://hub.docker.com/u/amazonDynamoDB Localプロビジョニングされたスループット、データストレージ、またはデータ転送のコストはありません。
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 483rd Party Fake https://localstack.cloud/
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 493rd 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
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 50https://localstack.cloud/3rd Party Fake
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Fake によるテストを、どの層に含めるか?51PureMock
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Fake によるテストを、どの層に含めるか?52PureMockFakeUnit Test ?
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Fake による Unit Testing の問題意識53• 外部の知識が十分でないとテストケースが書けない• 他のAWSサービスとの結合方法に対する知識が必要• Fakeモジュールに関する知識が必要 ( ie. Dockerでの起動、compose方法 )• テストが重くなるため、開発やデリバリーが低速化する。• イテレーションがし難くなる• 外部のアーキテクチャが変更された時にも、テストケースが容易に影響を受ける• テストの陳腐化が起り易い• テストのメンテナンスコストの増大• Test Case維持が属人化する• AWSサービスや、Fakeの識者でないと、テストケースから仕様やアーキテクチャが判断し難い
© 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 と呼ぶには規模が大きい
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Fake によるテストを、どの層に含めるか?55PureMockFakeIntegration Test ?
© 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 多数起動によるリソース枯渇?)
© 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上でやりたい
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 58PureMockFake はCodingフェーズには便利 (補足)FakeCoding中、Fakeを常駐させておき、対話させるなど便利
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 59ServerlessのIntegration Test
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 60Serverless Integration Testing on AWS
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Serverless は使った分だけのお支払い (おさらい)61• リクエスト数、ならびに処理の実行時間に応じた課金となり、実際の処理量と金額が比例する• 事前の初期投資が不要なので、コストゼロからのスタートが可能
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Multi Environment62EnvironmentDevelopment Pipeline Test Productionデリバリーライフサイクルに応じて環境を個別に用意する
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Multi Environment63デリバリーライフサイクルに応じて環境を個別に用意するEnvironmentDevelopment Pipeline Test ProductionServerless Serviceはご利用分の従量課金だから、環境分離に向いています
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.どう環境を分けるのか?64VPC SubnetRegion CloudFormationStackAccount
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.どう環境を分けるのか?65VPC SubnetRegion CloudFormationStackAccountServerless Serviceは、VPCやSubnetに依存していないものも多いため、難しい商用と同じ環境でStackのDeploy/Rollbackを、実行するのは危険Account単位のサービス上限のケアや、Region単位での、新サービスの対応状況の違いがある可能であれば、MultiAccout のデリバリーパイプラインを構築
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.EnvironmentDevelopment Pipeline Test ProductionMulti Account66デリバリーライフサイクルに応じて AWS Account を個別に用意するAccount Account AccountAccount
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.AWS Organizations を利用すると、Account管理が便利に67Organization Organization rootOUAWS accountsAdmin (master) AWS accountAWS accountsAWS accountsOUOUOUOUhttps://www.slideshare.net/AmazonWebServicesJapan/20180214-aws-blackbeltorganizations
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Cross Account Delivery Pipeline68DevelopersAWS Cloud AWS CloudAWS CloudAWS CloudAWS CodeCommitAWS CodeBuildAWS CodePipeline CloudFormationCloudFormationStackCloudFormationCloudFormationStackTest AccountProduction AccountPipeline AccountDevelopment AccountCross Accountにまたがる権限が必要https://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Cross Account Delivery Pipeline69AWS Cloud AWS Cloud AWS CloudAWS CodeCommitAWS CodeBuildAWS CodePipeline CloudFormationCloudFormationStackTest AccountPipeline AccountDevelopment AccountIAM RoleBucketIAM RoleIAM Rolehttps://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/Developers
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Cross Account Delivery Pipeline70AWS Cloud AWS Cloud AWS CloudAWS CodeCommitAWS CodeBuildAWS CodePipeline CloudFormationCloudFormationStackTest AccountPipeline AccountDevelopment AccountIAM RoleBucketIAM RoleCode CheckoutIAM RoleAssumeRolePut CodeCodeCommitからCodeをCheckouthttps://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/Developers
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.DevelopersCross Account Delivery Pipeline71AWS Cloud AWS Cloud AWS CloudAWS CodeCommitAWS CodeBuildAWS CodePipeline CloudFormationCloudFormationStackTest AccountPipeline AccountDevelopment AccountIAM RoleBucketIAM RoleCode CheckoutIAM RoleAssumeRolePut CodeTriggerSourceが checkout完了したら、CodeBuildを実⾏https://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Cross Account Delivery Pipeline72AWS Cloud AWS Cloud AWS CloudAWS CodeCommitAWS CodeBuildAWS CodePipeline CloudFormationCloudFormationStackTest AccountPipeline AccountDevelopment AccountIAM RoleBucketIAM RoleCode CheckoutIAM RoleAssumeRolePut CodeTriggerPut PackageCodeをビルドし、PackageをS3にPutするhttps://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/Developers
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Cross Account Delivery Pipeline73AWS Cloud AWS Cloud AWS CloudAWS CodeCommitAWS CodeBuildAWS CodePipeline CloudFormationCloudFormationStackTest AccountPipeline AccountDevelopment AccountIAM RoleBucketIAM RoleCode CheckoutIAM RoleAssumeRolePut CodeTriggerPut PackageAssumeRolePass the RoleCloudFormation 実⾏Executehttps://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/Developers
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Cross Account Delivery Pipeline74AWS Cloud AWS Cloud AWS CloudAWS CodeCommitAWS CodeBuildAWS CodePipeline CloudFormationCloudFormationStackTest AccountPipeline AccountDevelopment AccountIAM RoleBucketIAM RoleCode CheckoutIAM RoleAssumeRolePut CodeTriggerPut PackageAssumeRolePass the RoleExecutehttps://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/Developers
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Cross Account Delivery Pipeline75AWS Cloud AWS Cloud AWS CloudAWS CodeCommitAWS CodeBuildAWS CodePipeline CloudFormationCloudFormationStackTest AccountPipeline AccountDevelopment AccountIAM RoleBucketIAM RoleCode CheckoutIAM RoleAssumeRolePut CodeTriggerPut PackageAssumeRolePass the RoleExecuteCross Account でデリバリー完了!https://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/Developers
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.実際にIntegration Test してみよう76AWS CloudTest Accounthttps://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/DevelopersAWS CloudDevelopment AccountIntegration Test 対象サービス
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.実際にIntegration Test してみよう77AWS CloudTest Accounthttps://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/DevelopersAWS CloudDevelopment AccountContainerAmazon Elastic ContainerServiceテストシナリオを配備しておくテスト実⾏⽤のリソースを確保
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.実際にIntegration Test してみよう78AWS CloudTest Accounthttps://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/DevelopersAWS CloudDevelopment AccountContainerAmazon Elastic ContainerServiceテストシナリオを実⾏
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.実際にIntegration Test してみよう79AWS CloudTest Accounthttps://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/DevelopersAWS CloudDevelopment AccountContainerAmazon Elastic ContainerServiceテストシナリオを実⾏Cross Account でIntegration Test 完了!
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Test のためのリソース維持やコストが気になる?80AWS CloudTest Accounthttps://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/DevelopersAWS CloudDevelopment AccountContainerAmazon Elastic ContainerServiceテスト実⾏⽤のリソースを確保
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Test のためのリソース維持やコストが気になる?81AWS CloudTest Accounthttps://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/DevelopersAWS CloudDevelopment AccountContainerAmazon Elastic ContainerServiceテスト実⾏⽤のリソースを確保Test 用のリソースもServerlessで作るのは?
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Test のためのリソース維持やコストが気になる?82AWS CloudTest Accounthttps://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/DevelopersAWS CloudDevelopment AccountContainerAmazon Elastic ContainerService
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Test のためのリソース維持やコストが気になる?83AWS CloudTest Accounthttps://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/DevelopersAWS CloudDevelopment AccountfuntionAWS Lambdaテスト実⾏⽤のリソースをServerless化
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 84https://github.com/Nordstrom/serverless-artillery3rd Party
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 85https://github.com/Nordstrom/serverless-artillery3rd Party
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Test のためのリソース維持やコストが気になる?86AWS CloudTest Accounthttps://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/DevelopersAWS CloudDevelopment AccountfuntionAWS LambdaServerless-artilleryテストシナリオを配備しておく
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Test のためのリソース維持やコストが気になる?87AWS CloudTest Accounthttps://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/DevelopersAWS CloudDevelopment AccountfuntionAWS LambdaServerless-artilleryテストシナリオを実⾏
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Test のためのリソース維持やコストが気になる?88AWS CloudTest Accounthttps://aws.amazon.com/jp/blogs/devops/aws-building-a-secure-cross-account-continuous-delivery-pipeline/DevelopersAWS CloudDevelopment AccountfuntionAWS LambdaServerless-artilleryテストシナリオを実⾏Serverless による Serverless の試験完了!
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.Cross Account Delivery Pipeline with Testing89DevelopersAWS Cloud AWS CloudAWS CloudAWS CloudAWS CodeCommitAWS CodeBuildAWS CodePipeline CloudFormationCloudFormationStackCloudFormationStackTest AccountProduction AccountPipeline AccountDevelopment Accountテスト実⾏⽤Test RequestsTest Script
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 90まとめ
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.まとめ91• 今回は、サーバーレス のテスト方法の一部をご紹介しました。• 環境やプロダクトやビジネスに応じて、また、異なった戦略があるかもしれません。• ワークロードに適合する戦略を立てテストしましょう。• デプロイするだけで、実行されなければ課金されないという、サーバーレス の特徴を活かして、Multi Accountでテスト環境を整備するメリットもご紹介いたしました。• テスト効率を上げることによって、デリバリーパイプラインを高速化できます。• よりビジネスに貢献する開発に、その時間を当てることができます。• テストを自動化して、属人化したテスト手法を見直してみましょう。
© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved.© 2020, Amazon Web Services, Inc. or its affiliates. All rights reserved. 92Thank you !@_kensh