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
780
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
640
Amazon RDS / Amazon Aurora パフォーマンスチューニングとモニタリング
twingob
9
2.7k
短縮 URL サービス 4分間クッキング - Amazon CloudFront KeyValueStore, CloudFront Functions, AWS CDK で作成、CloudWatch Logs で簡易アクセス集計 -
twingob
1
1.2k
失敗知識から学ぶ!クラウドアプリ設計で避けるべき事例とその対策
twingob
11
5.5k
Amazon CodeCatalyst と Amazon CodeWhisperer で開発を加速しよう!
twingob
1
790
AWS Copilot with AWS CDK
twingob
1
540
Amazon Redshift Serverless with CDK
twingob
1
1.8k
Rapid Prototyping with AWS
twingob
0
480
Using cdk-remote-stack and AWS Edge Networking Services for cross-regional applications
twingob
0
370
Other Decks in Technology
See All in Technology
[TechNight #90-1] 本当に使える?ZDMの新機能を実践検証してみた
oracle4engineer
PRO
3
140
第9回情シス転職ミートアップ_テックタッチ株式会社
forester3003
0
120
ObsidianをMCP連携させてみる
ttnyt8701
2
140
25分で解説する「最小権限の原則」を実現するための AWS「ポリシー」大全 / 20250625-aws-summit-aws-policy
opelab
6
680
(非公式) AWS Summit Japan と 海浜幕張 の歩き方 2025年版
coosuke
PRO
1
320
LinkX_GitHubを基点にした_AI時代のプロジェクトマネジメント.pdf
iotcomjpadmin
0
160
登壇ネタの見つけ方 / How to find talk topics
pinkumohikan
2
160
AWS CDK 実践的アプローチ N選 / aws-cdk-practical-approaches
gotok365
4
450
AIにどこまで任せる?実務で使える(かもしれない)AIエージェント設計の考え方
har1101
3
1.2k
標準技術と独自システムで作る「つらくない」SaaS アカウント管理 / Effortless SaaS Account Management with Standard Technologies & Custom Systems
yuyatakeyama
2
990
データプラットフォーム技術におけるメダリオンアーキテクチャという考え方/DataPlatformWithMedallionArchitecture
smdmts
5
550
本当に使える?AutoUpgrade の新機能を実践検証してみた
oracle4engineer
PRO
1
120
Featured
See All Featured
Git: the NoSQL Database
bkeepers
PRO
430
65k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3.3k
Optimizing for Happiness
mojombo
379
70k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.5k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.3k
Designing Experiences People Love
moore
142
24k
GitHub's CSS Performance
jonrohan
1031
460k
The Power of CSS Pseudo Elements
geoffreycrofte
77
5.8k
Fireside Chat
paigeccino
37
3.5k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
181
53k
How to train your dragon (web standard)
notwaldorf
92
6.1k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
252
21k
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