サーバーレス のプラクティスを実践するために多くのコーディングをしていませんか?
ビジネスロジックに集中するために、プラクティスを素早く実現するLambda Powertoolsをご紹介します!
想定される聴講者 AWSサーバーレス をご利用されている方 よりプラクティカルなAWS Lambdaの運用を考えている方 サーバーレスサービス構築・運用に興味がある方
ゴール AWS Lambda Powertools の使い所を理解していただく
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.7th Oct 2020Kensuke ShimokawaAWS Lambda Powertoolsサーバーレスのプラクティスをシンプルに実現する@_kensh
View Slide
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Who am I?NameKensuke ShimokawaCompanyAmazon Web Services Japan K.K.RoleServerless Specialist Solutions Architect@_kensh
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.本セッションは想定される聴講者• AWSサーバーレス をご利用されている方• よりプラクティカルなAWS Lambdaの運用を考えている方• サーバーレスサービス構築・運用に興味がある方ゴール• AWS Lambda Powertools の使い所を理解していただく
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Table of contents• Serverless Lens について• AWS Lambda Powertools について• Logging• Trace• Metrics
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Serverless Lens
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.AWS Well-Architected Framework(W-A)とは?2015年 AWS re:Invent にて発表
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.AWS Well-Architected Frameworkホワイトペーパー設計原則と(質問と回答形式)のベストプラクティス集コストの最適化セキュリティ 信頼性パフォーマンス効率運⽤の優秀性
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.毎年アップデートServerless Lens : 2017年 AWS re:Invent にて発表
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Kindle版も無料でダウンロードできます
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.AWS Well-Architected Toolhttps://aws.amazon.com/jp/blogs/news/new-serverless-lens-in-aws-well-architected-tool/
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.AWS Serverless Application Lens
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.サーバーレス は分散アーキテクチャ静的コンテンツ動的データ記事/試合状況フォロー状況管理認可(フェデレーション)ログの保存ETL処理ログ収集 データ分析クローリング記事に対する処理(タグ付けなど)変更通知画像に対する処理(顔座標の検出)AmazonCloudWatchAWS X-Ray静的コンテンツ動的データ記事/試合状況フォロー状況管理ログの保存ETL処理ログ収集 データ分析クローリング記事に対する処理(タグ付けなど)変更通知画像に対する処理(顔座標の検出)静的コンテンツ動的データ記事/試合状況フォロー状況管理ログの保存ETL処理ログ収集 データ分析クローリング記事に対する処理(タグ付けなど)変更通知画像に対する処理(顔座標の検出)静的コンテンツ動的データ記事/試合状況クローリング記事に対する処理(タグ付けなど)変更通知画像に対する処理(顔座標の検出)
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.サーバーレス は分散アーキテクチャ静的コンテンツ動的データ記事/試合状況フォロー状況管理認可(フェデレーション)ログの保存ETL処理ログ収集 データ分析クローリング記事に対する処理(タグ付けなど)変更通知画像に対する処理(顔座標の検出)AmazonCloudWatchAWS X-Ray静的コンテンツ動的データ記事/試合状況フォロー状況管理ログの保存ETL処理ログ収集 データ分析クローリング記事に対する処理(タグ付けなど)変更通知画像に対する処理(顔座標の検出)静的コンテンツ動的データ記事/試合状況フォロー状況管理ログの保存ETL処理ログ収集 データ分析クローリング記事に対する処理(タグ付けなど)変更通知画像に対する処理(顔座標の検出)静的コンテンツ動的データ記事/試合状況クローリング記事に対する処理(タグ付けなど)変更通知画像に対する処理(顔座標の検出)© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved. '0 A9(9 65;7>*C D#-ETL%7)@ '2 C"D,1?:8$.%7CB/43&DAmazonCloudWatchAWS X-RayA9(9 65;7#-ETL%7)@ '2 C"D,1?:8$.%7CB/43&DA9(9 65;7#-ETL%7)@ '2 C"D,1?:8$.%7CB/43&DA9(9 C"D,1?:8$.%7CB/43&D
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.運用上の優秀性LogMetricsTraceAmazonCloudWatchAWS X-Ray
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Lambda Powertools
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.AWS Lambda Powertoolsパイプラインに必要なツールリソースを生成seminar-appアプリケーションに必要なリソースを生成上位Stack下位StackAWS SAMCloudFormationAWS LambdaPowertools運用上の優秀性をサポート
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.AWS Lambda Powertoolshttps://awslabs.github.io/aws-lambda-powertools-python/
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.AWS Lambda PowertoolsLogMetricsTraceAmazonCloudWatchAWS X-Ray
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Runtimeaws-samples / aws-lambda-powertools-python aws-samples / aws-lambda-powertools-java
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Logging
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Structured Logging (構造化ログ)[INFO] RawSemi-structuredStructured[INFO] ... {“message”: }{“level”: “INFO”, “message”: }Canonical [timestamp] meta=datatimestamp | operation | key=value |…SampleType
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Raw Logging - Before[INFO] 2020-01-31T22:.. 1c8df7d3… Hello worldResult[課題感]構造化されていないので検索性がよくない
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Semi-Structured Logging (半構造化ログ)- Before[INFO] … {“message”: “Hello world”}Result[課題感]構造化オブジェクトを自作する手間Log Levelも構造化したい
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Structured Logging (構造化ログ)- Before{"asctime": "2020-07-12...","levelname": "INFO","name": "root","message": "Aha!"}Result[課題感]構造化されたが、コードの可読性が損なわれる
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Structured Logging (構造化ログ)- After{"timestamp": "2020-07-14...","level": "INFO","location": "collect.handler:5","service": "payment","sampling_rate": 0.5,"message": ”Aha!”}Result[解消]構造化されており、記述も楽!
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Structured Logging (構造化ログ)- After{…"lambda_function_name":..,"lambda_function_memory_size": 128,"lambda_function_arn": ”…","lambda_request_id": "52fd..","message": ”Aha","cold_start": true}Result[解消]デコレータで関数Context情報も出力可能
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.CloudWatch Logs Insights
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.CloudWatch Logs Insights (Cold Start)
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Trace
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Trace の考え方TraceSegmentSub-segmentAPI Gateway Lambda FargateDynamoDBAPI GatewayS3 bucketType Key Value NamespaceAnnotation UserId a1c8k...Metadata Cart {….} Checkout凡例 Trace metadataAWS X-Ray
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.AWS SAMでLambdaのTraceをアクティベイト
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Trace / サービスマップResult
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Trace / サービスマップ - Before[課題感]パッチを当てる手間
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Trace / サービスマップ - BeforeResult
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Trace / サービスマップ - Before[課題感]Subsegmentを宣言する必要冗長な記述
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Trace / サービスマップ - After[解消]デコレータでサブセグメントも定義
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Trace / サービスマップ - AfterResult
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Metrics
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Metricsの概念
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Metricsの出力 - BeforeSynchronous[課題感]Metricのフォーマットに従うのが大変冗長!同期出力…
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Metricsの出力 - BeforeSynchronous[課題感]Metricのフォーマットに従うのが大変複数出力はさらに冗長!同期出力…
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Metricsの出力 - AfterAsynchronous[解消]Metricのフォーマットを意識しない非同期出力!
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Metricsの出力 - AfterAsynchronous[解消]Metricのフォーマット複数出力でも意識しない非同期出力!
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Metricsの出力 - AfterAsynchronousResultEmbedded Metric Formatを使用している
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Metricsの出力 - AfterResultビジネスKPIを可視化!
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.All In OneEnvironment variable ValuePOWERTOOLS_SERVICE_NAME shopping-cartPOWERTOOLS_METRICS_NAMESPACE e-commerce-appLOG_LEVEL INFO環境変数で名前空間を管理
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Utilities
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.AWS Lambda Powertools
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Parameter Store• 指定された時間(デフォルトは5秒)のパラメーター値をキャッシュ• JSONまたはbase64でエンコードされた文字列からパラメータ値を変換
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.SQS• 正常処理メッセージがSQSに返却されるのを防止• バッチメッセージを個別に処理するためのシンプルなインターフェイス
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.まとめ• Well-Architected Framework(WA)を使って、アーキテクチャのプラクティスの確認を行いましょう。• AWS Lambda Powertoolsを使って、手間がかかるWAの実践を便利にしてみましょう!
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Thank you !@_kensh
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Appendix
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.Demo examplesaws-samples / aws-serverless-airline aws-samples / aws-serverless-shopping-cart aws-samples / serverless-ecommerce-platform