🚀aws-lambda-managed-instances
- プラグイン
- aws-serverless
- 引数
- [describe your workload or what you need help with]
- ソース
- GitHub で見る ↗
説明
AWS Lambda マネージドインスタンス(LMI)へのワークロードの評価、設定、および移行を支援します。 次のような場合に使用: Lambda マネージドインスタンス、LMI、キャパシティプロバイダー、マルチ同時実行 Lambda、専用インスタンス Lambda、EC2 バックエンド Lambda、コールドスタートの排除、Graviton Lambda、Lambda のインスタンスタイプ、リザーブドインスタンスまたは Savings Plans を活用した Lambda コスト最適化について扱う場合。 また、コスト削減を目的とした高ボリュームかつ予測可能なワークロードを検討している場合や、安定した継続トラフィックにおける Lambda と EC2 の比較を行う場合にも使用します。 LMI を使用しない標準的な Lambda については、代わりに `aws-lambda` スキルを使用してください。
原文を表示
Evaluate, configure, and migrate workloads to AWS Lambda Managed Instances (LMI). Triggers on: Lambda Managed Instances, LMI, capacity provider, multi-concurrency Lambda, dedicated instance Lambda, EC2-backed Lambda, cold start elimination, Graviton Lambda, instance type for Lambda, Lambda cost optimization with Reserved Instances or Savings Plans. Also trigger when users describe high-volume predictable workloads seeking cost savings, or compare Lambda vs EC2 for steady-state traffic. For standard Lambda without LMI, use the aws-lambda skill instead.
ユースケース
- ✓Lambda マネージドインスタンスへのワークロード評価
- ✓LMI への移行を検討するとき
- ✓Lambda のコスト最適化を行うとき
- ✓高ボリュームで予測可能なワークロードを検討するとき
- ✓Lambda と EC2 の比較を行うとき
本文(日本語訳)
AWS Lambda Managed Instances (LMI)
AWSがプロビジョニング、パッチ適用、スケーリング、ルーティング、ロードバランシングを管理しながら、お使いのアカウント内の現行世代EC2インスタンス上でLambda関数を実行します。Lambdaの開発者エクスペリエンスと、EC2の料金体系およびハードウェアオプションを組み合わせたサービスです。
標準的なLambda開発については aws-lambda skill を、SAM/CDKによるデプロイについては aws-serverless-deployment skill を参照してください。
参照ファイルの読み込みタイミング
- コスト比較、料金分析、Lambda vs LMIのコスト、Savings Plans、または Reserved Instances → references/cost-comparison.md を参照
- インスタンスタイプ、メモリサイジング、vCPU比率、スケーリングチューニング、または キャパシティプロバイダーの設定 → references/configuration-guide.md を参照
- スレッドセーフティ、並行処理モデル、コードレビューチェックリスト、Powertoolsの互換性、または マルチ同時実行への対応状況 → references/thread-safety.md を参照
- 移行前後のコード例、ランタイム別の移行手順(Node.js、Python、Java、.NET)、または コネクションプーリング → references/migration-patterns.md を参照
- IAMロール、VPCの設定、CLIコマンド、SAMテンプレート、または CDKの例 → references/infrastructure-setup.md および scripts/setup-lmi.sh を参照
- エラー、スロットリング、デバッグ、または デプロイが進まない場合 → references/troubleshooting.md を参照
LMIはこのワークロードに適しているか? 簡易判断チャート
| 判断基準 | LMIが有力な選択肢 | 標準Lambdaが適切 |
|---|---|---|
| トラフィック | 安定・予測可能・月間5,000万リクエスト以上 | バースト的・予測不能・長時間アイドル |
| コスト | スケール時に実行時間のコストが大きい | 呼び出しが少ない・散発的 |
| コールドスタート | 許容不可(プロビジョニング済みキャパシティではLMIが排除;スケールアウト時に短い遅延が発生する場合あり) | 許容可能、またはSnapStartで緩和済み |
| コンピュート | 最新CPU・特定ファミリー・高ネットワーク帯域幅 | 標準LambdaのメモリおよびCPUで十分 |
| 分離性 | アカウント内の専有EC2インスタンス・完全なVPC制御 | 共有Firecracker マイクロVMで問題なし |
| ゼロスケール | 不要(実行環境は常時起動) | 必須(アイドル時は無課金にしたい) |
| コードの対応状況 | スレッドセーフ(Node.js / Java / .NET)またはPythonの任意のコード | スレッドアンセーフなNode.js / Java / .NETで変更コストが高い |
手順
ステップ1: ワークロードを評価する
推奨を行う前に以下の情報を収集してください。
- トラフィックパターン: 安定しているかバースト的か?1秒あたりのリクエスト数は?
- 現在のコスト: Lambdaの月間費用は?既存のSavings Plansは?
- ランタイム: Node.js、Java、.NET、Pythonのいずれか?
- メモリ/CPU: 必要メモリ量は?CPUバウンドかI/Oバウンドか?
- 実行時間: 平均値とP99は?
- 同時実行への対応状況: スレッドセーフティの状況(Node.js / Java / .NET)は?
/tmpパスの共有は?呼び出しごとのDBコネクションは? - VPC: すでにVPC内に配置されているか?プライベートリソースへのアクセスは必要か?
ステップ2: コスト比較を作成する
必須: LMIを推奨する前にコスト比較を提示してください。最低限、以下のシナリオを比較します。
| シナリオ | 有利な条件 |
|---|---|
| Lambda オンデマンド | 低ボリューム・バースト的トラフィック |
| LMI オンデマンド | 高ボリューム・安定したトラフィック |
目安: Lambdaの月間費用が安定したトラフィックで約1,000ドルを超えると、LMIのコスト競争力が生まれます。
割引分析(Savings Plans、Reserved Instances)については、AWSの料金計算ツールおよび計算式と具体的な例が掲載されている references/cost-comparison.md をユーザーに案内してください。 割引の推奨はワークロード固有の予測が必要なため、このskillの対応範囲外となります。
ステップ3: デプロイ設定を構成する
インスタンスファミリー(約450種類): Cシリーズ(コンピュート・.xlarge以上)、Mシリーズ(汎用・.large以上)、Rシリーズ(メモリ・.large以上)。 価格性能比の観点からARM(Graviton)を推奨します。
メモリ対vCPU比率: 2:1(コンピュート)、4:1(汎用・デフォルト)、8:1(メモリ)。 最小2GB・最大32GB。
マルチ同時実行のデフォルト値(vCPUあたり): Node.js 64、Java 32、.NET 32、Python 16。
スケーリング: MinExecutionEnvironments(デフォルト3)、MaxVCpuCount(デフォルト400)、TargetResourceUtilization。
デシジョンツリーと詳細なチューニングについては references/configuration-guide.md を参照してください。
ステップ4: コードを移行する
同時実行の安全性についてコードをレビューしてください。 LMIは1つの実行環境内で複数の呼び出しを並行して実行しますが、その動作モデルはランタイムによって異なります。
- Python: プロセスベースの分離 — グローバル変数は共有されません。スレッドセーフティの変更は不要です。
/tmpの競合とメモリサイジング(プロセスあたりのメモリ × 同時実行数)に注意してください。 - Node.js: ワーカースレッド — グローバル変数はワーカー内で共有されます。非同期の安全性が必要です。コールバック形式のハンドラーはNode.js 22ではサポートされていません。
- Java / .NET: OSスレッド / タスク — ハンドラーはスレッド間で共有されます。完全なスレッドセーフティが必要です。
全ランタイム共通の注意点: /tmpパスの共有、呼び出しごとのDBコネクション。
スレッドセーフティの注意点(Node.js / Java / .NETのみ): ミュータブルなグローバル変数、スレッドセーフでないライブラリ。
レビューチェックリストは references/thread-safety.md、ランタイム別の移行前後のコード例は references/migration-patterns.md を参照してください。
ステップ5: インフラをセットアップする
- IAMロールを2つ作成する: 実行ロール(関数用)とオペレーターロール(キャパシティプロバイダーによるEC2管理用)
- 複数のAZにサブネットを持つVPCを設定する(可用性向上のため3AZ以上を推奨)
- VPC設定とスケーリング制限を指定してキャパシティプロバイダーを作成する
- キャパシティプロバイダーをアタッチして関数を作成または更新する
- バージョンを発行する(インスタンスのプロビジョニングがトリガーされます)
CLIコマンドとSAMテンプレートについては references/infrastructure-setup.md を参照してください。
ステップ6: 検証とカットオーバー
- まず非本番環境にデプロイする
- CloudWatchでCPU使用率・メモリ・同時実行数・スロットリング率を監視する
- 重み付きエイリアスを使って段階的にトラフィックを移行する(10% → 50% → 100%)
- 1〜2週間の本番データをもとにコストを比較する
- 安定したら標準Lambdaを廃止する
ベストプラクティス
設定
- 推奨: 4:1の比率とランタイムデフォルトの同時実行数から始める
- 推奨: x86依存がない限りARM(Graviton)を使用する
- 推奨: 特定のハードウェアが必要でない限り、インスタンスタイプはLambdaに選択させる
- 推奨: MaxVCpuCountを設定してコストの上限を管理する
- 非推奨: 本番環境でMinExecutionEnvironmentsを3未満に設定すること(マルチAZカバレッジが低下します)。非本番環境では最小値を1に設定しても構いません。
- 非推奨: インスタンスタイプを過度に限定すること(可用性が低下します)
移行
- 推奨: I/Oヘビーな関数から始める(マルチ同時実行の恩恵が最も大きい;CPUバウンドな関数は同一CPUを奪い合います)
- 推奨: キャパシティプロバイダーにアタッチする前にコードの同時実行安全性をレビューする(Node.js / Java / .NETはスレッドセーフティ;Pythonは
/tmpとメモリを確認) - 推奨: 重み付きエイリアスを使って段階的にトラフィックを移行する
- 推奨: すべてのログ出力にリクエストIDを含める
- 推奨: DBプールとSDKクライアントはハンドラーの外側で初期化する
- 推奨: 最大同時実行時の
/tmp使用量の合計を見積もる - 非推奨: リクエスト固有の名前付けなしにハードコードされた
/tmpパスへの書き込み - 非推奨: コスト比較をスキップすること — LMIが常に安いとは限りません
運用
- 推奨: スロットリング率が1%超・CPU使用率が80%超の場合にCloudWatchアラームを設定する
- 非推奨: LMIのEC2インスタンスを手動で終了すること(代わりにキャパシティプロバイダーを削除してください)
- 非推奨: バージョンの発行を忘れること — 発行されていない関数はLMI上で実行できません
リソース制限 クイックリファレンス
| リソース | 制限 |
|---|---|
| メモリ | 最小2GB・最大32GB |
| 同時実行数/vCPU | 64(Node.js)、32(Java / .NET)、16(Python) |
| インスタンスの寿命 | 約12時間(Lambdaが自動的に置き換えます) |
| 実行環境(EE)の寿命 | 約4時間(Lambdaが自動的に置き換えます) |
| ランタイム | Node.js、Java、.NET、Python |
| インスタンスファミリー | C(.xlarge以上)、M(.large以上)、R(.large以上) |
| スケーリング | スロットリングなしで5分以内に2倍に拡張 |
トラブルシューティング クイックリファレンス
| 問題 | 原因 | 対処方法 |
|---|---|---|
| 429スロットリング | トラフィックがスケーリング速度を超過 | MinExecutionEnvironmentsを増やすか、TargetResourceUtilizationを下げる |
| 関数がPENDING状態のまま | インスタンスのプロビジョニング中 | しばらく待つ;VPC / IAMの設定を確認する |
| アーキテクチャの不一致 | 関数とキャパシティプロバイダーのアーキテクチャが異なる | 両者を同じアーキテクチャに揃える |
| インスタンスを終了できない | キャパシティプロバイ |
原文(English)を表示
AWS Lambda Managed Instances (LMI)
Run Lambda functions on current-generation EC2 instances in your account while AWS manages provisioning, patching, scaling, routing, and load balancing. Combines Lambda's developer experience with EC2's pricing and hardware options.
For standard Lambda development, see aws-lambda skill. For SAM/CDK deployment, see aws-serverless-deployment skill.
When to Load Reference Files
- Cost comparison, pricing analysis, Lambda vs LMI cost, Savings Plans, or Reserved Instances -> see references/cost-comparison.md
- Instance types, memory sizing, vCPU ratios, scaling tuning, or capacity provider config -> see references/configuration-guide.md
- Thread safety, concurrency model, code review checklist, Powertools compatibility, or multi-concurrency readiness -> see references/thread-safety.md
- Before/after code examples, runtime-specific migration (Node.js, Python, Java, .NET), or connection pooling -> see references/migration-patterns.md
- IAM roles, VPC setup, CLI commands, SAM template, or CDK example -> see references/infrastructure-setup.md and scripts/setup-lmi.sh
- Errors, throttling, debugging, or stuck deployments -> see references/troubleshooting.md
Quick Decision: Is LMI Right for This Workload?
| Signal | LMI is a strong fit | Standard Lambda is better |
|---|---|---|
| Traffic | Steady, predictable, 50M+ req/mo | Bursty, unpredictable, long idle |
| Cost | Duration-heavy spend at scale | Low or sporadic invocations |
| Cold starts | Unacceptable (LMI eliminates for provisioned capacity; scale-out may have brief delays) | Tolerable or mitigated by SnapStart |
| Compute | Latest CPUs, specific families, high network bandwidth | Standard Lambda memory/CPU sufficient |
| Isolation | Dedicated EC2 instances in your account, full VPC control | Shared Firecracker micro-VMs acceptable |
| Scale-to-zero | Not needed (execution environments always running) | Required (pay nothing when idle) |
| Code readiness | Thread-safe (Node.js/Java/.NET) or any Python code | Non-thread-safe Node.js/Java/.NET, expensive to change |
Instructions
Step 1: Assess the Workload
Gather these signals before recommending:
- Traffic pattern: Steady vs bursty? Requests per second?
- Current costs: Monthly Lambda spend? Existing Savings Plans?
- Runtime: Node.js, Java, .NET, or Python?
- Memory/CPU: How much memory? CPU-bound or I/O-bound?
- Execution duration: Average and P99?
- Concurrency readiness: Thread safety (Node.js/Java/.NET)? Shared
/tmppaths? Per-invocation DB connections? - VPC: Already in a VPC? Private resource access needed?
Step 2: Build the Cost Comparison
REQUIRED: Present a cost comparison before recommending LMI. Compare at minimum:
| Scenario | When it wins |
|---|---|
| Lambda on-demand | Low volume, bursty traffic |
| LMI on-demand | High volume, steady traffic |
Rule of thumb: LMI becomes cost-competitive when your Lambda spend exceeds ~$1,000/month with steady traffic.
For discount analysis (Savings Plans, Reserved Instances), refer users to the AWS Pricing Calculator and references/cost-comparison.md for formulas and worked examples. Discount recommendations require workload-specific forecasting beyond this skill's scope.
Step 3: Configure the Deployment
Instance families (~450 types): C-series (compute, .xlarge+), M-series (general, .large+), R-series (memory, .large+). ARM (Graviton) for best price-performance.
Memory-to-vCPU ratios: 2:1 (compute), 4:1 (general, default), 8:1 (memory). Min 2 GB, max 32 GB.
Multi-concurrency defaults/vCPU: Node.js 64, Java 32, .NET 32, Python 16.
Scaling: MinExecutionEnvironments (default 3), MaxVCpuCount (default 400), TargetResourceUtilization.
See references/configuration-guide.md for decision trees and detailed tuning.
Step 4: Migrate the Code
Review code for concurrency safety. LMI runs multiple invocations concurrently per execution environment, but the model differs by runtime:
- Python: Process-based isolation — globals are NOT shared. No thread-safety changes needed. Focus on
/tmpconflicts and memory sizing (per-process × concurrency). - Node.js: Worker threads — globals shared within a worker. Requires async safety. Callback handlers not supported on Node.js 22.
- Java/.NET: OS threads/Tasks — handler shared across threads. Requires full thread safety.
Common issues (all runtimes): shared /tmp paths, per-invocation DB connections.
Thread-safety issues (Node.js/Java/.NET only): mutable globals, non-thread-safe libs.
See references/thread-safety.md for the review checklist and references/migration-patterns.md for runtime-specific before/after code.
Step 5: Set Up Infrastructure
- Create two IAM roles: execution role (for the function) and operator role (for capacity provider EC2 management)
- Configure VPC with subnets across multiple AZs (recommended 3+ for resiliency)
- Create capacity provider with VPC config and scaling limits
- Create or update function with capacity provider attachment
- Publish a version (triggers instance provisioning)
See references/infrastructure-setup.md for CLI commands and SAM templates.
Step 6: Validate and Cut Over
- Deploy to a non-production environment first
- Monitor CloudWatch: CPU utilization, memory, concurrency, throttle rate
- Gradual traffic shift with weighted aliases (10% → 50% → 100%)
- Compare costs after 1-2 weeks of production data
- Decommission standard Lambda once stable
Best Practices
Configuration
- Do: Start with 4:1 ratio and runtime default concurrency
- Do: Use ARM (Graviton) unless x86 dependencies exist
- Do: Let Lambda choose instance types unless specific hardware needed
- Do: Set MaxVCpuCount to control cost ceiling
- Don't: Set MinExecutionEnvironments below 3 in production (reduces multi-AZ coverage). Non-prod environments can use 1 as the minimum.
- Don't: Over-restrict instance types (lowers availability)
Migration
- Do: Start with I/O-heavy functions (benefit most from multi-concurrency; CPU-bound functions compete for same CPU)
- Do: Review code for concurrency safety before attaching to capacity provider (thread safety for Node.js/Java/.NET;
/tmpand memory for Python) - Do: Use weighted aliases for gradual traffic shift
- Do: Include request IDs in all log statements
- Do: Initialize DB pools and SDK clients outside the handler
- Do: Estimate total
/tmpusage under max concurrency - Don't: Write to hardcoded
/tmppaths without request-unique naming - Don't: Skip cost comparison — LMI is not always cheaper
Operations
- Do: Set CloudWatch alarms on throttle rate > 1% and CPU > 80%
- Don't: Manually terminate LMI EC2 instances (delete the capacity provider instead)
- Don't: Forget to publish a version — unpublished functions cannot run on LMI
Limits Quick Reference
| Resource | Limit |
|---|---|
| Memory | 2 GB min, 32 GB max |
| Concurrency/vCPU | 64 (Node.js), 32 (Java/.NET), 16 (Python) |
| Instance lifespan | ~12 hours (auto-replaced by Lambda) |
| EE lifespan | ~4 hours (auto-replaced by Lambda) |
| Runtimes | Node.js, Java, .NET, Python |
| Instance families | C (.xlarge+), M (.large+), R (.large+) |
| Scaling | Doubles within 5 min without throttles |
Troubleshooting Quick Reference
| Issue | Cause | Fix |
|---|---|---|
| 429 throttles | Traffic exceeds scaling speed | Increase MinExecutionEnvironments or lower TargetResourceUtilization |
| Function stuck PENDING | Provisioning instances | Wait; check VPC/IAM config |
| Architecture mismatch | Function ≠ capacity provider arch | Align both to same architecture |
| Cannot terminate instances | Managed by capacity provider | Delete capacity provider instead |
| Race conditions | Code not thread-safe | See references/thread-safety.md |
See references/troubleshooting.md for detailed resolution steps.
Configuration
AWS CLI Setup
REQUIRED: AWS credentials configured on the host machine.
Verify access: Run aws sts get-caller-identity
Regional Availability
Currently available: us-east-1, us-east-2, us-west-2, ap-northeast-1, eu-west-1. Expanding to all commercial regions soon.
Check the Lambda Managed Instances documentation for the latest regional availability.
Language Selection
Default: TypeScript
Override: "use Python" → Python, "use JavaScript" → JavaScript. When not specified, ALWAYS use TypeScript.
IaC Framework Selection
Default: CDK
Override: "use SAM" → SAM YAML, "use CloudFormation" → CloudFormation YAML. When not specified, ALWAYS use CDK.
Error Scenarios
Serverless MCP Server Unavailable
- Inform user: "AWS Serverless MCP not responding"
- Ask: "Proceed without MCP support?"
- DO NOT continue without user confirmation
Unsupported Runtime
- State: "Lambda Managed Instances does not yet support [runtime]"
- List supported runtimes
- Suggest standard Lambda as alternative
Unsupported Region
- State: "Lambda Managed Instances is not yet available in [region]"
- List available regions
Resources
原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。