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
580
Amazon RDS / Amazon Aurora パフォーマンスチューニングとモニタリング
twingob
8
2.2k
短縮 URL サービス 4分間クッキング - Amazon CloudFront KeyValueStore, CloudFront Functions, AWS CDK で作成、CloudWatch Logs で簡易アクセス集計 -
twingob
1
1k
失敗知識から学ぶ!クラウドアプリ設計で避けるべき事例とその対策
twingob
11
5.3k
Amazon CodeCatalyst と Amazon CodeWhisperer で開発を加速しよう!
twingob
1
740
AWS Copilot with AWS CDK
twingob
1
490
Amazon Redshift Serverless with CDK
twingob
1
1.7k
Rapid Prototyping with AWS
twingob
0
450
Using cdk-remote-stack and AWS Edge Networking Services for cross-regional applications
twingob
0
330
Other Decks in Technology
See All in Technology
第13回 Data-Centric AI勉強会, 画像認識におけるData-centric AI
ksaito_osx
0
360
Developer Summit 2025 [14-D-1] Yuki Hattori
yuhattor
19
5.1k
スタートアップ1人目QAエンジニアが QAチームを立ち上げ、“個”からチーム、 そして“組織”に成長するまで / How to set up QA team at reiwatravel
mii3king
1
1.1k
CZII - CryoET Object Identification 参加振り返り・解法共有
tattaka
0
240
転生CISOサバイバル・ガイド / CISO Career Transition Survival Guide
kanny
2
390
Moved to https://speakerdeck.com/toshihue/presales-engineer-career-bridging-tech-biz-ja
toshihue
2
550
管理者しか知らないOutlookの裏側のAIを覗く#AzureTravelers
hirotomotaguchi
1
240
SA Night #2 FinatextのSA思想/SA Night #2 Finatext session
satoshiimai
1
100
開発者が自律的に AWS Security Hub findings に 対応する仕組みと AWS re:Invent 2024 登壇体験談 / Developers autonomously report AWS Security Hub findings Corresponding mechanism and AWS re:Invent 2024 presentation experience
kaminashi
0
190
家電アプリ共通PF "Linova" のAPI利用とPostman活用事例ご紹介
yukiogawa
0
130
室長と気ままに学ぶマイクロソフトのビジネスアプリケーションとビジネスプロセス
ryoheig0405
0
320
Googleマップ/Earthが一般化した 地図タイルのイマ
mapconcierge4agu
1
200
Featured
See All Featured
A better future with KSS
kneath
238
17k
Visualization
eitanlees
146
15k
Documentation Writing (for coders)
carmenintech
67
4.6k
Code Review Best Practice
trishagee
66
17k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.3k
The Cult of Friendly URLs
andyhume
78
6.2k
Being A Developer After 40
akosma
89
590k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
40
2k
Site-Speed That Sticks
csswizardry
3
370
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Making the Leap to Tech Lead
cromwellryan
133
9.1k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
29
4.6k
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