Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
AWS Lambda Powertools
Search
@twingo_b
November 03, 2020
Technology
2
710
AWS Lambda Powertools
AWS Lambda のちょっと便利なツールのご紹介
2020/11/03 合同勉強会 in 大都会岡山 - 2020 Winter Online -
資料
@twingo_b
November 03, 2020
Tweet
Share
More Decks by @twingo_b
See All by @twingo_b
20240713 Generative AI with AWS
twingob
6
500
Amazon RDS / Amazon Aurora パフォーマンスチューニングとモニタリング
twingob
6
1.5k
短縮 URL サービス 4分間クッキング - Amazon CloudFront KeyValueStore, CloudFront Functions, AWS CDK で作成、CloudWatch Logs で簡易アクセス集計 -
twingob
1
830
失敗知識から学ぶ!クラウドアプリ設計で避けるべき事例とその対策
twingob
11
4.9k
Amazon CodeCatalyst と Amazon CodeWhisperer で開発を加速しよう!
twingob
1
680
AWS Copilot with AWS CDK
twingob
1
440
Amazon Redshift Serverless with CDK
twingob
1
1.5k
Rapid Prototyping with AWS
twingob
0
400
Using cdk-remote-stack and AWS Edge Networking Services for cross-regional applications
twingob
0
290
Other Decks in Technology
See All in Technology
JAWS-UG 事務局 の「これまで」から みんなで「ここから」を考えよう
miu_crescent
2
140
VueとViteで作るUIコンポーネントライブラリ ~デザインシステムとプロダクトの理想的な分離を目指して~ / 20241019_cloudsign_VueFesJapan2024_1
bengo4com
8
3k
塩野義製薬様のAWS統合管理戦略:Organizations設計と運用の具体例
tkikuchi
0
300
データ分析基盤のためにS3を深堀りする~アーキテクチャ設計の考え方のヒントに~
nrinetcom
PRO
1
740
俺とVSCode Python Debugger Extension
sat
PRO
1
140
LLMOps : ΔMLOps
shuntaito
5
770
さくっと実践!Postmanを活用した高品質で持続可能なAPI管理
yokawasa
5
350
KongによるAPIライフサイクル マネジメント
hashitokyo
1
160
なぜ Rack を理解すべきかプレトーク / Why should you understand Rack - Pre-talk
hogelog
0
220
MobileActOsaka_241018.pdf
akaitadaaki
0
100
From LibreOffice to « La Suite » : providing civil servants with Free Software sovereign tools
bluehats
0
120
パートナー企業のテクニカルサポートエンジニアとして気になる、より良い AWS サポートの利活用について
kazzpapa3
0
180
Featured
See All Featured
Rails Girls Zürich Keynote
gr2m
93
13k
Fontdeck: Realign not Redesign
paulrobertlloyd
81
5.2k
Teambox: Starting and Learning
jrom
132
8.7k
Typedesign – Prime Four
hannesfritz
39
2.3k
The Language of Interfaces
destraynor
154
24k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
23k
Documentation Writing (for coders)
carmenintech
65
4.4k
How to Ace a Technical Interview
jacobian
275
23k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
YesSQL, Process and Tooling at Scale
rocio
167
14k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
No one is an island. Learnings from fostering a developers community.
thoeni
19
2.9k
Transcript
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. 2020/11/3 Amazon Web Services Japan K.K. Solutions Architect Yoshinori Fujiwara AWS Lambda のちょっと便利な ツールのご紹介 サーバーレスしてますか! @twingo_b 〜 合同勉強会 in 大都会岡山 - 2020 Winter Online - 〜
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. サーバーレスショッピングカート
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. サーバーレスショッピングカート
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. サーバーレスショッピングカート
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. サーバーレスショッピングカート Amazon API Gateway を使用して HTTP REST API を提供
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. サーバーレスショッピングカート AWS Lambda は役割 および HTTP Method 毎に関数を分離
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. サーバーレスショッピングカート バックエンドにも (外部) HTTP API が 存在
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. サーバーレスショッピングカート Amazon SQS キュー を使った非同期処理
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. サーバーレスショッピングカート Amazon DynamoDB と DynamoDB Streams に よるストリーム処理
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. サーバーレスショッピングカート • Amazon API Gateway を使用して HTTP REST API を提供 • バックエンドにも (外部) HTTP API が存在 • AWS Lambda は役割および HTTP Method 毎に関数を分離 • Amazon SQS キューを使った非同期処理 • Amazon DynamoDB と DynamoDB Streams によるストリーム処理
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. サーバーレスアプリケーションの よくある運用の悩み
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. サーバーレスショッピングカート 各 Lambda 関数のエラ ーをどうやって監視し たら良いの?
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. サーバーレスショッピングカート バックエンドの HTTP API はどの Lambda 関数から 呼ばれているの?
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. サーバーレスショッピングカート ボトルネックはどこにあ るの?
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. サーバーレスショッピングカート 非同期処理やストリー ミング処理は正常稼働 しているの?
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. サーバーレスアプリケーションのよくある運用の悩み • 各 Lambda 関数のエラーをどうやって監視したら良いの? • バックエンドの HTTP API はどの Lambda 関数から呼ばれているの? • ボトルネックはどこにあるの? • 非同期処理やストリーミング処理は正常稼働しているの?
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. サーバーレス は分散アーキテクチャ 静的コンテンツ 動的データ 記事/試合状況 フォロー状況管理 認可 (フェデレーション) ログの保存 ETL処理 ログ収集 データ分析 クローリング 記事に対する処理 (タグ付けなど) 変更通知 画像に対する処理 (顔座標の検出) Amazon CloudWatch AWS X-Ray 静的コンテンツ 動的データ 記事/試合状況 フォロー状況管理 ログの保存 ETL処理 ログ収集 データ分析 クローリング 記事に対する処理 (タグ付けなど) 変更通知 画像に対する処理 (顔座標の検出) 静的コンテンツ 動的データ 記事/試合状況 フォロー状況管理 ログの保存 ETL処理 ログ収集 データ分析 クローリング 記事に対する処理 (タグ付けなど) 変更通知 画像に対する処理 (顔座標の検出) 静的コンテンツ 動的データ 記事/試合状況 クローリング 記事に対する処理 (タグ付けなど) 変更通知 画像に対する処理 (顔座標の検出)
© 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. AWS Lambda Powertools https://awslabs.github.io/aws-lambda-powertools-python/
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. AWS Lambda Powertools ログ メトリ クス トレース Amazon CloudWatch AWS X-Ray
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Lambda Powertools 生成 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. Lambda Powertools 生成 CloudWatch サービスマップ
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Lambda Powertools 生成 CloudWatch トレース
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Lambda Powertools 生成 CloudWatch カスタムメトリクス ビジネスメトリクスの可視化に利用可能
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Lambda Powertools 対応言語 aws-samples / aws-lambda-powertools-python aws-samples / aws-lambda-powertools-java
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. ロギング
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. 構造化ログ (Structured Logging) を推奨 [INFO] <timestamp> <msg> Raw Semi-structured Structured [INFO] ... {“message”: <msg> } {“level”: “INFO”, “message”: <msg> } Canonical [timestamp] <operation> meta=data timestamp | operation | key=value |… Sample Type
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. これまでの Lambda ログ [INFO] 2020-01-31T22:.. 1c8df7d3… Hello world Result [課題] 構造化されていないので検索性が よくない
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. 自作の半構造化ログ [INFO] … {“message”: “Hello world”} Result [課題] 構造化オブジェクトを自作する手間 Log Level も構造化したい
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. 自作の構造化ログ { "asctime": "2020-07-12...", "levelname": "INFO", "name": "root", "message": "Aha!" } Result [課題] 構造化されたが、コードの 可読性が損なわれる
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Lambda Powertools の構造化ログ { "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. Lambda Powertools の構造化ログ { … "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. トレーシング
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. トレーシング の考え方 トレーシング セグメント サブセグメント API Gateway Lambda Fargate DynamoDB API Gateway S3 bucket Type Key Value Namespace Annotation UserId a1c8k... Metadata Cart {….} Checkout 凡例 Trace metadata AWS X-Ray
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. AWS SAM で Lambda のトレーシングを有効化
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. これまでのトレーシング / サービスマップ [課題] パッチを当てる手間がある
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. これまでのトレーシング / サービスマップ [課題] Subsegment を個別に宣言する必要あり 冗長な記述
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Lambda Powertools のトレーシング / サービスマップ [解消] デコレータでサブセグメントも定義
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. メトリクス
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. メトリクス の概念
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. これまでのメトリクス出力 Synchronous [課題] Metric のフォーマットに 従うのが大変 冗長! 同期出力…
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. これまでのメトリクス出力 Synchronous [課題感] Metricのフォーマットに 従うのが大変 複数出力はさらに冗長! 同期出力…
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Lambda Powertools メトリクス出力 Asynchronous [解消] Metric のフォーマット を意識しない 非同期出力!
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Lambda Powertools メトリクス出力 Asynchronous [解消] Metric のフォーマット 複数出力でも意識しない 非同期出力!
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Lambda Powertools メトリクス出力 Asynchronous Result Embedded Metric Format を使用している
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Lambda Powertools はオールインワン Environment variable Value POWERTOOLS_SERVICE_NAME shopping-cart POWERTOOLS_METRICS_NAMESPACE e-commerce-app LOG_LEVEL INFO 環境変数で名前空間を管理
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. ユーティリティ
© 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. AWS Systems Manager Parameter Store, AWS Secrets Manager, Amazon DynamoDB • 指定された時間(デフォルト は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. Lambda Powertools を活用しましょう! aws-samples / aws-lambda-powertools-python aws-samples / aws-lambda-powertools-java
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. AWS Lambda Powertools 活用デモアプリ aws-samples / aws-serverless-airline aws-samples / aws-serverless-shopping-cart aws-samples / serverless-ecommerce-platform