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
SAM + FastAPI + Mangum でお手軽サーバーレス
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
abimaru
June 09, 2025
Technology
470
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
SAM + FastAPI + Mangum でお手軽サーバーレス
SAM + FastAPI + Mangum でお手軽サーバーレス
Strands Agents SDKをFastAPIに統合して、動くか試してみました。
abimaru
June 09, 2025
More Decks by abimaru
See All by abimaru
モノレポ × DevContainere 設計パターン
kugimiya
1
490
Other Decks in Technology
See All in Technology
無理せず続ける、子育てエンジニアの学び
codmoninc
PRO
0
930
M5Stackで作る BLEマウス GPSログの世界
tomokusaba
PRO
0
430
夫婦で子育てするための育児標準化
codmoninc
PRO
0
400
NDIでApple Vision Proにリアルタイム映像送信
jyouryuusui
0
120
Persisting Massive Data with Rails ~Designing for 60 billion rows, and fighting the bottlenecks~ Railsで挑む大量データ永続化 〜600億件を永続化するための設計とボトルネックとの戦い〜
occhi
0
730
大型犬好きによるPugの紹介
yamanoku
1
160
Getting Started with Google Antigravity
glaforge
0
310
ソフトウェア ファクトリー - 再現性のあるソフトウェアの工場づくり / Software factory
iktakahiro
6
5k
Benchmarking Disaggregated Serving on vLLM + Dynamo with a Real Coding-Agent Workload
nttcom
1
190
スキマバイトという雇用形態は存在しないので、雇用期間1日のアルバイト契約を事業者とワーカーが結ぶ手続きを支えるのがタイミーなんです
akitoshiga
0
200
Gemini Intelligence 入門 ― AppFunctions と Gemini Nano
takuroabe
0
280
二歩目のフロントエンド・ウェブアクセシビリティ
camiha
2
640
Featured
See All Featured
Building an army of robots
kneath
307
47k
Git: the NoSQL Database
bkeepers
PRO
433
67k
Done Done
chrislema
187
17k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
2
2.2k
How to Talk to Developers About Accessibility
jct
2
580
Rebuilding a faster, lazier Slack
samanthasiow
85
9.7k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.8k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
220
GitHub's CSS Performance
jonrohan
1033
470k
Being A Developer After 40
akosma
92
590k
Transcript
SAM + FastAPI + Mangum で お手軽サーバーレス Strands Agents SDK
使ってみた 2025/06/07 JAWS-UG OITA 発表 @あびまる(釘宮) JAWS-UG 発表資料
自己紹介 名前: あびまる(釘宮) 所属: 株式会社スリーシェイク 経験言語: TypeScript, Golang, Python, Kotlin
環境: AWS, Google Cloud etc… GitHub: https://github.com/daikugimiya0715 JAWS-UG 発表資料 2
今日話すこと SAM + FastAPI + Mangumを使ったサーバーレスAPI開発について説明します。 その後に、Strands Agent SDKを統合した物のデモをします。 1.
なぜ SAM + FastAPI + Mangum なのか 2. 実装のポイント 3. コスト効率とスケーラビリティ 4. OpenAPI と Swagger の活用 5. 生成 AI 時代の Python 活用 6. デモ: Strands SDK 統合 JAWS-UG 発表資料 3
課題: API 開発の悩み 開発環境のセットアップが面倒 インフラコストが心配 スケーラビリティの考慮 ドキュメント生成の手間 生成 AI SDK
との統合 JAWS-UG 発表資料 4
解決策: SAM + FastAPI + Mangum 3 つの技術を組み合わせた現代的なアプローチ SAM: Infrastructure
as Code でインフラ管理 FastAPI: 高速で直感的な API 開発 Mangum: サーバーレス環境での ASGI 実行 メリット 開発効率: 型安全で高速な開発 コスト効率: 使った分だけの課金 運用効率: サーバー管理不要 + JAWS-UG 発表資料 5
SAM (Serverless Application Model) AWS 公式のサーバーレス開発フレームワーク Infrastructure as Code: YAML
でインフラ定義 ローカル開発: sam local start-api で即座にテスト 簡単デプロイ: sam build && sam deploy SAM の強み CloudFormation 拡張: AWS リソースを簡潔に定義 依存関係管理: 自動的にパッケージングとデプロイ 実際のメリット 学習コスト低: CloudFormation より簡単 デバッグ効率: ローカルで API をテスト可能 JAWS-UG 発表資料 6
FastAPI + Mangum FastAPI の特徴 自動 OpenAPI 生成: /docs で即座に
API 仕様確認 型安全: Python の型ヒントでバグ防止 高パフォーマンス: 非同期処理対応 Mangum の役割 ASGI ブリッジ: FastAPI を Lambda で実行 Zero Configuration: 設定不要で動作 ECS 移行対応: 同じコードでコンテナ化可能 JAWS-UG 発表資料 7
実装例 from fastapi import FastAPI from mangum import Mangum from
pydantic import BaseModel app = FastAPI(title="サーバーレス API") class Item(BaseModel): name: str price: int @app.post("/items/") async def create_item(item: Item): return {"item": item, "status": "created"} # Lambda用ハンドラー handler = Mangum(app) JAWS-UG 発表資料 8
なぜサーバーレスなのか? コスト面のメリット アイドル時コストゼロ: 使用していない時は課金なし 従量課金: リクエスト数に応じた課金 予算管理: 使用量に応じた透明な課金 運用面のメリット サーバー管理不要:
インフラ運用から解放 自動スケーリング: トラフィック増加に自動対応 ECS 移行: コード変更なしで可能 ← これが本当に嬉しい 実際の開発環境では月額数百円程度で運用可能! JAWS-UG 発表資料 9
なぜ Python なのか? 豊富な AI/ML 系 SDK OpenAI, Anthropic, AWS
Bedrock Langchain, LlamaIndex etc… データサイエンスエコシステム # 最新のAI SDKが揃っている import openai import anthropic import boto3 # Bedrock from strands import Agent # 今回のデモ JAWS-UG 発表資料 10
ついでに Strands SDK 使ってみる 実装例 from strands import Agent from
strands.models import BedrockModel # Bedrock Claude を使用 bedrock_model = BedrockModel( model_id="claude-3-sonnet", region_name="ap-northeast-1" ) agent = Agent( model=bedrock_model, tools=[calculator, shell, use_aws] ) @app.post("/chat") async def chat_with_agent(message: str): response = await agent.stream_async(message) return StreamingResponse(response) JAWS-UG 発表資料 11
実際のディレクトリ構成 fast-api-sam/ ├── app/ │ ├── __init__.py │ └── main.py
# FastAPI アプリ ├── template.yaml # SAM テンプレート ├── samconfig.toml # SAM 設定 ├── pyproject.toml # Python 依存関係 └── tests/ └── test_main.py # テスト JAWS-UG 発表資料 12
実際に動かしてみた結果 invoke エンドポイントの実行例 確認できたこと API が正常に動作: エンドポイントが期待通りにレスポンス S3 バケット情報取得: agent
のツールコール (use_aws) Stream レスポンス: Agent を使った Stream レスポンスの実装 JAWS-UG 発表資料 13
実際の運用メリット 開発体験 ローカル開発が快適 型安全性 自動ドキュメント生成 豊富なエコシステム 運用面 コスト効率 自動スケーリング メンテナンス不要
AWS 統合 JAWS-UG 発表資料 14
まとめ SAM + FastAPI + Mangum の価値 POCから本格運用まで一気通貫で対応できる、モダンなサーバーレスAPI開発スタッ クです。 1.
開発効率: 現代的な API 開発体験 2. コスト効率: 使った分だけの従量課金 3. 拡張性: ECS への移行も容易 4. AI 統合: Python 生態系の恩恵 5. ドキュメント: 自動生成で保守コスト削減 JAWS-UG 発表資料 15
質疑応答 ご質問をお待ちしています! GitHub: https://github.com/daikugimiya0715 X: https://x.com/abimaruXD ありがとうございました! JAWS-UG 発表資料 16
補足: 参考リンク AWS SAM FastAPI Mangum Strands SDK JAWS-UG 発表資料
17