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
790
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
660
Amazon RDS / Amazon Aurora パフォーマンスチューニングとモニタリング
twingob
9
2.9k
短縮 URL サービス 4分間クッキング - Amazon CloudFront KeyValueStore, CloudFront Functions, AWS CDK で作成、CloudWatch Logs で簡易アクセス集計 -
twingob
1
1.3k
失敗知識から学ぶ!クラウドアプリ設計で避けるべき事例とその対策
twingob
11
5.7k
Amazon CodeCatalyst と Amazon CodeWhisperer で開発を加速しよう!
twingob
1
810
AWS Copilot with AWS CDK
twingob
1
550
Amazon Redshift Serverless with CDK
twingob
2
1.9k
Rapid Prototyping with AWS
twingob
0
500
Using cdk-remote-stack and AWS Edge Networking Services for cross-regional applications
twingob
0
380
Other Decks in Technology
See All in Technology
UDDのススメ - 拡張版 -
maguroalternative
1
550
Rubyの国のPerlMonger
anatofuz
3
740
Amazon Qで2Dゲームを作成してみた
siromi
0
140
Intro to Software Startups: Spring 2025
arnabdotorg
0
260
マルチプロダクト×マルチテナントを支えるモジュラモノリスを中心としたアソビューのアーキテクチャ
disc99
1
550
「AIと一緒にやる」が当たり前になるまでの奮闘記
kakehashi
PRO
3
150
人に寄り添うAIエージェントとアーキテクチャ #BetAIDay
layerx
PRO
9
2.2k
Bet "Bet AI" - Accelerating Our AI Journey #BetAIDay
layerx
PRO
4
1.8k
AI時代の経営、Bet AI Vision #BetAIDay
layerx
PRO
1
2k
React Server ComponentsでAPI不要の開発体験
polidog
PRO
0
260
Segment Anything Modelの最新動向:SAM2とその発展系
tenten0727
0
770
Google Agentspaceを実際に導入した効果と今後の展望
mixi_engineers
PRO
3
700
Featured
See All Featured
Building a Scalable Design System with Sketch
lauravandoore
462
33k
Scaling GitHub
holman
461
140k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
131
19k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
50k
The World Runs on Bad Software
bkeepers
PRO
70
11k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
36
2.5k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
31
2.2k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
Building an army of robots
kneath
306
45k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
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