Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Bedrock AgentをサポートしたPowertools for AWS Lambdaによ...
Search
fujioka-a
June 25, 2025
Technology
450
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Bedrock AgentをサポートしたPowertools for AWS Lambdaによる開発の効率化・省力化
Media-JAWS x JAWS-UG千葉支部 #2 幕張よ我々は帰ってきた!で発表した資料です(一部編集してます)
fujioka-a
June 25, 2025
More Decks by fujioka-a
See All by fujioka-a
DevOps Agentで運用判断をチーム資産にする~Agent InstructionsとAgent Skillを継続的に育てる~
fujioka6789
0
270
【re:Invent2025 Notion reCap】AIエージェントを制御する “Agent SOP(Standard Operating Procedures)”をチームで継続的に管理・更新する
fujioka6789
0
46
re:Invent2025 大阪reCap “Agent SOP(Standard Operating Procedures)”で手軽に管理・更新できるAIエージェントを構築しよう
fujioka6789
0
110
re:Invent初参加でも120%満喫するための心構え@フォージビジョンre:Invent報告会
fujioka6789
0
300
書籍推薦AIエージェントを作ってみよう ワークショップ
fujioka6789
0
29
Other Decks in Technology
See All in Technology
コスト最適化の「めんどくさい」を AWS FinOps Agent でチョット楽にする
classmethod_kaz
0
300
生成AIのテナント制御とシャドーMCP対策 | AIを"止めずに"、情報を守る
yukun
0
150
From Vanilla Kubernetes to a Batteries-Included Platform: Developer Experience at 1,300+ Clusters
yosshi_
0
680
20260912_スクフェス三河
kgnkhkr
0
270
目の前の楽しいが人生を変える - コミュニティの螺旋の歩き方と楽しむコツ / change your life
soudai
PRO
4
390
薬剤師(ドメインエキスパート)と一緒に育てる薬局向けAIアシスタント
kakehashi
PRO
2
140
Microsoft 365 Copilot chat -tekoälypalvelun tietosuojaongelmat
hponka
0
660
omasushiというライブラリを作った
polidog
PRO
0
200
AIに丸投げしないトイル削減 / Eliminating Toil Without Leaving It All to AI
kohbis
4
1.1k
AIで開発は速くなったのに、なぜ現場は楽にならないのか 〜あなたの組織のボトルネックを突き止めるワークショップ〜
jacopen
1
320
ASTを使って影響範囲を特定する
nealle
0
140
幾何アルゴリズムで なめらかなピン操作を / iOSDC Japan 2026 / smoothpin
kazumanagano
0
260
Featured
See All Featured
Into the Great Unknown - MozCon
thekraken
41
2.7k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
490
Skip the Path - Find Your Career Trail
mkilby
1
220
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
270
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
57k
Faster Mobile Websites
deanohume
310
32k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
4.7k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
500
Bash Introduction
62gerente
615
220k
Designing for humans not robots
tammielis
254
26k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.4k
Transcript
MEDIA-JAWS X JAWS-UG千葉支部#2 幕張よ我々は帰ってきた! 2025.6.25(火) Bedrock Agentをサポートした Powertools for AWS
Lambdaによる 開発の効率化・省力化
自己紹介 藤岡 敦史 前職:バックエンドエンジニア、 農業系や建設系のクライアントにて開発 現職:フォージビジョン所属、 インフラエンジニア、 フルスタックに多数のクライアントにて開発・構築 2025 All
AWS Certifications Engineer →ゴールドジャケット受け取れました!! 好きなAWSサービス Lambda
はじめに そもそも”Powertools”とは… ※もっと詳しく知りたい方は、ぜひ以下のAWS福井さんの資料を参照ください(個人的に神資料です) https://pages.awscloud.com/rs/112-TZM- 766/images/20221124_24th_ISV_DiveDeepSeminar_Lambda_Powertools.pdf Powertools • OSSライブラリ • ロギング、トレース、メトリクスなど、
ベストプラクティスの型・実装パターンがある程度 決まっている機能を手軽に導入できる →ボイラープレートを減らすことで、 開発速度やメンテナンス性を向上させられる • 以下の言語をサポート • Python • Java • TypeScript • .NET
従来のCore utilities • 以降の説明は、今回検証に使用したTypeScriptを前提に説明します • 以下がPowertoolsの主要機能(ユーティリティ)です ※言語によってユーティリティの充実度はマチマチです ユーティリティ 概要 トレース
X-rayと連携した処理のトレース ログ 構造化ロギング メトリクス カスタム名前空間を利用したメトリクス集計 Event Handler AppSync AppSync Eventからのパブリッシュ&サブスクライブ に対するイベントハンドリング ※他にも沢山ユーティリティはあるので、公式サイトを確認ください https://docs.powertools.aws.dev/lambda/typescript/latest/
最新のCore utilities • 今回新たに、Bedrock AgentからLambdaを呼び出しする際に必要とする、 Lambda側での決まった実装パターンがユーティリティ化された →自前実装せずPowertoolsを使用することで、実装が大きく効率化される! ユーティリティ 概要 トレース
X-rayと連携した処理のトレース ログ 構造化ロギング メトリクス カスタム名前空間を利用したメトリクス集計 Event Handler AppSync AppSync Eventからのパブリッシュ&サブスクライブ に対するイベントハンドリング Bedrock Agent Bedrock Agentからの呼び出し に対するイベントハンドリング ※2025.6.22時点で、Pythonと.NETはBedrock Agentとの連携が対応しているようです (Javaはまだ無いようです)
Event Handler(Bedrock Agent) とは • 今回の新機能は、Powertools公式に以下の概要図で説明されています。
Event Handler(Bedrock Agent) とは • 今回の新機能は、Powertools公式に以下の概要図で説明されています。 Bedrock AgentとのIN/OUT や、 tool
useのルーティング (適切なLambdaへの誘導)
とりあえず一回動かしてみよう • 検証のために、Bedrock Agent + Lambda + Powertoolsで、 Google Books
API を使った書籍推薦エージェントを作成しました • 全体として、以下のような流れで動きます
とりあえず一回動かしてみよう デモ
Lambda実装を確認しよう // importは割愛 const app = new BedrockAgentFunctionResolver({ logger });
// Bedrock Agent – Lambda間のリゾルバ // Toolsの定義(searchBooks) app.tool<{ keywords: string, author: string }>( async ({ keywords, author }, { event }) => { try { // Tool logic const books = await searchBooks(keywords, author, 10); return books.map(book => ({ ...book })); } catch (error) { logger.error('error search books', { error }); const {sessionAttributes, promptSessionAttributes, knowledgeBasesConfiguration} = event; return new BedrockFunctionResponse({ responseState: 'FAILURE', body: 'Error search books', sessionAttributes, promptSessionAttributes, knowledgeBasesConfiguration, }); } }, { // BedrockAgentFunctionResolverが、Tool useとして識別するメタデータ name: 'searchBooks', description: 'Search for books by author or keywords', } ); export const handler = async (event: unknown, context: Context) => { return app.resolve(event as BedrockAgentFunctionEvent, context); }; まずミニマム版から
Lambda実装を確認しよう // importは割愛 const app = new BedrockAgentFunctionResolver({ logger });
// Bedrock Agent – Lambda間のリゾルバ // Toolsの定義(searchBooks) app.tool<{ keywords: string, author: string }>( async ({ keywords, author }, { event }) => { try { // Tool logic const books = await searchBooks(keywords, author, 10); return books.map(book => ({ ...book })); } catch (error) { logger.error('error search books', { error }); const {sessionAttributes, promptSessionAttributes, knowledgeBasesConfiguration} = event; return new BedrockFunctionResponse({ responseState: 'FAILURE', body: 'Error search books', sessionAttributes, promptSessionAttributes, knowledgeBasesConfiguration, }); } }, { // BedrockAgentFunctionResolverが、Tool useとして識別するメタデータ name: 'searchBooks', description: 'Search for books by author or keywords', } ); export const handler = async (event: unknown, context: Context) => { return app.resolve(event as BedrockAgentFunctionEvent, context); }; まずミニマム版から ①中間のリゾルバを作成 ②Bedrock Agentからの入力をリゾルブ ③メタデータから一致するToolを特定(今回で言えば”searchBooks”) ④-1. リゾルバから受け渡されるパラメータを受け取って、処理実行 ④-2. Bedrock Agentへ、エラーをRaise
Powertoolsを使用しないと、以下が必要 (リゾルバが無いので、)Eventから1つ1つパラメータ取得するための実装 • アクショングループ • Tool名 などなど Bedrock AgentへRaiseするExceptionクラスなどを、 自前で作成・メンテする
そもそも、Bedrock Agentからのイベントが期待する形式なのか チェックしないといけない • Eventが期待する形式か • パラメータは適切か(バリデーション) Powertoolsを導入することで、 実装の削減のみ限らず、メンテナンス性や可読性も 向上することができる!
実際に完成したLambda(コアのLog、Trace、Metricsを含む) 前半 import type { Context } from 'aws-lambda'; import
{ BedrockAgentFunctionResolver, BedrockFunctionResponse } from '@aws-lambda-powertools/event-handler/bedrock-agent'; import type { BedrockAgentFunctionEvent } from '@aws-lambda-powertools/event-handler/types'; import { Metrics, MetricUnit } from '@aws-lambda-powertools/metrics'; import { Tracer } from '@aws-lambda-powertools/tracer'; import { searchBooks } from './bookModules.js'; import { logger } from './logger.js'; const tracer = new Tracer({serviceName: 'searchBooksAgent'}); const metrics = new Metrics({namespace: 'searchBooks‘, serviceName: 'searchBooksAgent'}); const app = new BedrockAgentFunctionResolver({ logger }); // Bedrock Agent – Lambda間のリゾルバ app.tool<{ keywords: string, author: string }>( async ({ keywords, author }, { event }) => { // 以降の全ロギングに対して、以下パラメータを表示 logger.appendKeys({ keywords, author, tool: 'searchBooks' }); logger.info('searchBooks called'); try { const books = await searchBooks(keywords, author, 10); metrics.addMetric('searchBooksSucceeded', MetricUnit.Count, 1); return books.map(book => ({ ...book })); } catch (error) { トレースとメトリクスを宣言 構造化ログへのパラメータ付与 ToolUse確認のためのメトリクス集計
実際に完成したLambda(コアのLog、Trace、Metricsを含む) 後半 } catch (error) { logger.error('error search books', {
error }); metrics.addMetric('searchBooksFailed', MetricUnit.Count, 1); const {sessionAttributes, promptSessionAttributes, knowledgeBasesConfiguration} = event; return new BedrockFunctionResponse({ responseState: 'FAILURE', body: 'Error search books', sessionAttributes, promptSessionAttributes, knowledgeBasesConfiguration, }); } }, { name: 'searchBooks', description: 'Search for books by author or keywords', } ); export const handler = async (event: unknown, context: Context) => { logger.logEventIfEnabled(event); logger.setCorrelationId((event as BedrockAgentFunctionEvent).sessionId); logger.appendKeys({ requestId: context.awsRequestId }); return app.resolve(event as BedrockAgentFunctionEvent, context); }; Toolがエラーした場合にメトリクス へインクリメント (アラートと連携などできる) 複数サービス間のトレースをしやす いように、CorrelationIdを ロガーに設定 任意のキーをロガーに設定 (今回はrequestId)
LOG (Log group) • 構造的なログが得られる • 指定したキー(Ex. correlation_id, requestId)や、 パラメータ(tool,
keywords, author(今回は指定してないので無し))を自動的に出力 { "level": "DEBUG", "message": "Searching books", "timestamp": "2025-06-23T11:56:24.726Z", "service": "book-search-agent", "sampling_rate": 0, "xray_trace_id": "1-685940e8-694b07215e21870b3ea377b4", "correlation_id": "228342203262808", "requestId": "a6bc05c2-20e9-419d-ba75-f5497abcaa0b", "keywords": "[AWS 生成AI, 初心者向け, 機械学習入門]", "tool": "searchBooks", "maxResults": 10 }
Metrics (カスタム名前空間へのPUT) • Tool実行のカウントや、処理内部の部分的な実行時間(Duration)などを メトリクス化することができる • アラームやダッシュボードなどと連携することで、エージェントの運用に役立つ
TRACE (AWS X-ray) • トレースは重要。有効化しておきましょう。 • 複数のToolを構築している場合に、どのToolが呼ばれているか追跡しやすい • AgentとTool、外部APIなどとの問題切り分けに強力
まとめ • PowertoolsでBedrock Agentがサポートされるようになった • 導入することで、大幅な実装手間を削減することができ、 開発生産性に加えて、メンテナンス性や可読性を向上させることができる • さらに、従来のユーティリティ(トレース、ログ、メトリクスなど)と組み合わせることで、 Tool
の開発や運用を快適に行うことができる 生成AIエージェントの開発・運用を加速させることができる!! Powertoolsを積極活用しましょう!!
ご清聴ありがとうございました Thank you for your listening.