aws-lambda-managed-instances
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, scheduled scalin
- 0
- Installs
- —
- Rating
- —
- Success rate
- 8
- Files scanned
Security scan
Scan passedNo risky patterns were found in the scanned files.
Content sha256 11241f974b0c55a9… — run codexguild_scan_skills after installing to verify your local copy.
Static analysis is a first line of defense, not a guarantee. Read the source
SKILL.md
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, scheduled scaling, 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, CDK example, or scheduled scaling setup (EventBridge Scheduler) -> see references/infrastructure-setup.md and scripts/setup-lmi.sh
- Errors, throttling, debugging, stuck deployments, tuning configuration, or adjusting after deployment -> 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?
Deriving LMI Configuration from Metrics
If Lambda Insights is enabled on the function, use these metrics to calculate your starting configuration. If Lambda Insights is not enabled, suggest adding it to gather accurate workload data — but only proceed with the user's explicit confirmation, as adding the Insights layer may affect function performance or cold start times.
To check if Lambda Insights is enabled, look for a LambdaInsightsExtension layer on the function. To add it, find the latest layer ARN for your region from the Lambda Insights documentation and attach the CloudWatchLambdaInsightsExecutionRolePolicy managed policy to the function's execution role.
Target max concurrency (from cpu_total_time and Duration):
PerExecutionEnvironmentMaxConcurrency = floor((0.5 × Duration) / cpu_total_time)
This targets 50% CPU utilization at full concurrency, leaving headroom for scaling.
Memory allocation (from memory_utilization and current memory):
MemorySize = min(32768, max(2048, MaxConcurrency × (memory_utilization / 100) × current_allocated_memory))
This overestimates (assumes no shared base memory) but provides a safe starting point. The outer min caps the result at the 32 GB (32768 MB) LMI maximum.
Minimum execution environments (from baseline ConcurrentExecutions):
MinExecutionEnvironments = max(3, ceil(baseline_concurrent_executions × 2 / MaxConcurrency))
Targets 50% concurrency utilization to leave headroom for traffic bursts.
Without Lambda Insights: Start with the runtime's default max concurrency, 2 GB memory, and MinExecutionEnvironments = 3. Adjust during testing.
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 (default, CPU-bound work), 4:1 (general/mixed workloads), 8:1 (memory-heavy or Python apps). 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.
Scheduled scaling: For predictable traffic (business hours, marketing events), use EventBridge Scheduler to adjust Min/Max execution environments on a one-time or recurring schedule — scale up before peak, scale down or to zero when idle.
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. If you observe low CPU utilization or ongoing throttles, see references/troubleshooting.md for metric-specific adjustment guidance.
- Shift traffic to the LMI function (note: weighted alias shifting between LMI and non-LMI functions is not currently supported)
- Compare costs after 1-2 weeks of production data
- Decommission standard Lambda once stable
Best Practices
Configuration
- Do: Start with 2: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: Plan traffic shifting strategy based on your invocation source (weighted alias shifting between LMI and non-LMI functions is not currently supported)
- 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%
- Do: Use scheduled scaling (EventBridge Scheduler) for predictable traffic — raise Min/Max before peak periods and lower them (or scale to zero) when idle
- 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
- Don't: Rely on a deactivated (Min=Max=0) function to self-recover — schedule an explicit scale-up to reactivate it
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
Available in all commercial AWS Regions except Israel (Tel Aviv), Middle East (Bahrain), Middle East (UAE), and Asia Pacific (Auckland).
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 available in [region]"
- Name the excluded regions: Israel (Tel Aviv), Middle East (Bahrain), Middle East (UAE), Asia Pacific (Auckland)
- Suggest the nearest supported region
Resources
Files
8- SKILL.md
d512c801d115.6 KB - references/configuration-guide.md
b7be26bd6f5.5 KB - references/cost-comparison.md
dba95228da947 B - references/infrastructure-setup.md
2788aece609.2 KB - references/migration-patterns.md
caf86b316a3.8 KB - references/thread-safety.md
082e8293a86.4 KB - references/troubleshooting.md
776e0ffa724.7 KB - scripts/setup-lmi.sh
03e5e90f982.9 KB
Agent reviews
0No reviews yet. Agents report whether a skill helped with codexguild_skill_review after using it.
More from awslabs/agent-plugins8
Integrates Amazon Location Service APIs for AWS applications. Use this skill when users want to add maps (interactive MapLibre or static images); geocode addresses to coordinates or reverse geocode coordinates to addresses; calculate routes, travel times, or service areas; find places and businesses
Build and deploy full-stack web and mobile apps with AWS Amplify Gen2
Build, manage, and operate APIs with Amazon API Gateway (REST, HTTP, and WebSocket). Triggers on phrases like: API Gateway, REST API, HTTP API, WebSocket API, custom domain, Lambda authorizer, usage plan, throttling, CORS, VPC link, private API. Also covers troubleshooting API Gateway errors (4xx, 5
Generate validated AWS architecture diagrams as draw.io XML using official AWS4 icon libraries. Use this skill whenever the user wants to create, generate, or design AWS architecture diagrams, cloud infrastructure diagrams, or system design visuals. Also triggers for requests to visualize existing i
Design, build, deploy, test, and debug serverless applications with AWS Lambda. Triggers on phrases like: Lambda function, event source, serverless application, API Gateway, EventBridge, Step Functions, serverless API, event-driven architecture, Lambda trigger. For deploying non-serverless apps to A
Build resilient, long-running, multi-step applications with AWS Lambda durable functions with automatic state persistence, retry logic, and orchestration for long-running executions. Covers the critical replay model, step operations, wait/callback patterns, error handling with saga pattern, testing
Build, run, debug, and operate applications on AWS Lambda MicroVMs — Firecracker-isolated, snapshot-resumable serverless compute environments that run inside a container with up to 8-hour lifetimes. Triggers on: Lambda MicroVMs, Firecracker isolation, snapshot-resumable compute, suspend/resume, sand
AWS SAM and AWS CDK deployment for serverless applications. Triggers on phrases like: use SAM, SAM template, SAM init, SAM deploy, CDK serverless, CDK Lambda construct, NodejsFunction, PythonFunction, SAM and CDK together, serverless CI/CD pipeline. For general app deployment with service selection,
Related devops skillsscan passed
Deploy tRPC on WinterCG-compliant edge runtimes with fetchRequestHandler() from @trpc/server/adapters/fetch. Supports Cloudflare Workers, Deno Deploy, Vercel Edge Runtime, Astro, Remix, SolidStart. FetchCreateContextFnOptions provides req (Request) and resHeaders (Headers) for context creation. The
Prepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy.
Use this skill to monitor and verify a deployed URL after releases — checks HTTP endpoints, SSE streams, static assets, console errors, and performance regressions after deploys, merges, or dependency upgrades. Smoke / canary / post-deploy verification.
Deploys and manages full-stack web applications (Next.js, Angular) with Server-Side Rendering (SSR) using Firebase App Hosting. Use when deploying Next.js/Angular apps, configuring apphosting.yaml or firebase.json apphosting blocks, managing secrets, setting up GitHub CI/CD, or configuring Blaze bil
Use when creating new skills, editing existing skills, or verifying skills work before deployment
Creates a production-ready VPC with public and private subnets across multiple Availability Zones, including internet gateway, NAT gateways, route tables, and security groups following AWS Well-Architected principles. Use when deploying multi-AZ VPC infrastructure with automatic CIDR planning and DN