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
760
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
600
Amazon RDS / Amazon Aurora パフォーマンスチューニングとモニタリング
twingob
9
2.4k
短縮 URL サービス 4分間クッキング - Amazon CloudFront KeyValueStore, CloudFront Functions, AWS CDK で作成、CloudWatch Logs で簡易アクセス集計 -
twingob
1
1.1k
失敗知識から学ぶ!クラウドアプリ設計で避けるべき事例とその対策
twingob
11
5.3k
Amazon CodeCatalyst と Amazon CodeWhisperer で開発を加速しよう!
twingob
1
760
AWS Copilot with AWS CDK
twingob
1
510
Amazon Redshift Serverless with CDK
twingob
1
1.7k
Rapid Prototyping with AWS
twingob
0
460
Using cdk-remote-stack and AWS Edge Networking Services for cross-regional applications
twingob
0
340
Other Decks in Technology
See All in Technology
みんなで育てるNewsPicksのSLO
troter
4
930
セキュリティグループの”タイプ”を改めて考えてみる
masakiokuda
0
150
技術的負債を正しく理解し、正しく付き合う #phperkaigi / PHPerKaigi 2025
shogogg
0
490
PHPStan をできる限り高速化してみる
colopl
0
170
非エンジニアにも伝えるメールセキュリティ / Email security for non-engineers
ykanoh
6
970
なぜ「Event Sourcing」を選択したのか〜事実に基づくことの重要性〜/Why did we choose "Event Sourcing"?
bitkey
1
330
ドメインイベントを活用したPHPコードのリファクタリング
kajitack
0
570
モジュラーモノリスでスケーラブルなシステムを作る - BASE のリアーキテクチャのいま
panda_program
5
930
Github Copilot Chatは本日よりケ◯ロ軍曹でありま〜〜〜すッ!!!(たぶん)
yu_yukk_y
1
110
いまから始めるAWS CDK 〜モダンなインフラ構築入門〜/iac-night-cdk-introduction
tomoki10
8
2.2k
組織に持ち込む脅威モデリング
nikinusu
2
630
30代エンジニアが考える、エンジニア生存戦略~~セキュリティを添えて~~
masakiokuda
3
1.2k
Featured
See All Featured
We Have a Design System, Now What?
morganepeng
51
7.5k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
6
600
Automating Front-end Workflow
addyosmani
1369
200k
Building Adaptive Systems
keathley
40
2.4k
KATA
mclloyd
29
14k
Java REST API Framework Comparison - PWX 2021
mraible
29
8.4k
Building a Scalable Design System with Sketch
lauravandoore
462
33k
Optimising Largest Contentful Paint
csswizardry
34
3.1k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.2k
Embracing the Ebb and Flow
colly
84
4.6k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2.1k
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