Aws lambda managed instances

From aws/agent-toolkit-for-aws · View interactive version

Aws lambda managed instances is an AI agent skill from the GitHub repository aws/agent-toolkit-for-aws. Evaluates, configures, and migrates workloads to AWS Lambda Managed Instances (LMI). Runs Lambda Event Functions on EC2 instances in the user's account while AWS manages provisioning, patching, and scaling. Triggers when queries mention Lambda Managed Instances, LMI, capacity providers, multi-concur

How to use this skill

Skill file

AWS Lambda Managed Instances (LMI)

Runs Lambda Event Functions on EC2 instances in the user's account while AWS manages provisioning, patching, scaling, routing, and load balancing. Combines Lambda's developer experience with EC2's pricing and hardware options.

Works best with the AWS MCP server for sandboxed CLI execution and audit logging. All guidance also works with standard AWS CLI or SAM CLI.

Note: Confirm regional availability, quotas, and instance type offerings against current AWS documentation before production deployment.

Quick Decision: Is LMI Right for This Workload?

| Signal | LMI is a strong fit | Lambda Event Functions are better |

|--------|---------------------|---------------------------|

| Traffic | Steady, predictable, 50M+ req/mo | Bursty, unpredictable, long periods of no traffic |

| Duration | Long-running asynchronous/ESM jobs that exceed 30 min (up to 90 min on LMI): ETL/data processing, media transcoding, ML inference, financial calc, web scraping | Short invocations; synchronous work needing >30 min (not supported on any Lambda) |

| Cost | Duration-heavy spend at scale | Low or sporadic invocations |

| Cold starts | Unacceptable (LMI eliminates for provisioned capacity) | Tolerable |

| Compute | Latest CPUs, specific families, high network bandwidth, NVIDIA GPUs (inference, transcoding, rendering) | Lambda Event Functions memory/CPU sufficient |

| Isolation | Dedicated EC2 instances in your account, full VPC control | Shared Firecracker micro-VMs acceptable |

| Scale-to-zero | Does not scale to zero but can create custom schedules with AWS provided solutions | Required (pay nothing when idle) |

| Code readiness | Thread-safe (Node.js/Java/.NET) or any Python code | Non-thread-safe code, expensive to change |

Routing

Read ONLY the single reference file that matches the user's task. Do not preload multiple references.

| User need | Action |

|-----------|--------|

| Cost comparison, pricing analysis, Savings Plans, Reserved Instances | Read cost-comparison.md |

| Instance types, memory sizing, vCPU ratios, scaling tuning, capacity provider config, SOCI lazy loading for large container images | Read configuration-guide.md |

| Thread safety, concurrency model, code review checklist, multi-concurrency readiness | Read thread-safety.md |

| Before/after code examples, runtime-specific migration, connection pooling | Read migration-patterns.md |

| IAM roles, VPC setup, CLI commands, SAM template, CDK example | Read infrastructure-setup.md |

| Errors, throttling, debugging, stuck deployments | Read troubleshooting.md |

| GPU-accelerated functions: accelerator memory, GPU instances, GPU base images (vLLM, SGLang, PyTorch), GPU concurrency, GPU errors | Read gpu-acceleration.md |

Troubleshooting quick facts (always mention when diagnosing issues):

Workflow

Step 1: Assess the Workload

Gather these signals before recommending:

  1. Traffic pattern: Steady vs bursty? Requests per second?
  2. Current costs: Monthly Lambda spend? Existing Savings Plans?
  3. Runtime: Node.js, Java, .NET, or Python?
  4. Memory/CPU: How much memory? CPU-bound or I/O-bound?
  5. Execution duration: Average and P99?
  6. Concurrency readiness: Thread safety? Shared /tmp paths? Per-invocation DB connections?
  7. VPC: Already in a VPC? Private resource access needed?
  8. GPU: Does the workload need a GPU (CUDA, PyTorch, vLLM, NVENC, OpenGL)? If yes, read gpu-acceleration.md.

Long-running asynchronous/ESM jobs that exceed 30 min are a positive fit — LMI supports a function timeout up to 90 min (5400s) for asynchronous and event-source-mapping invocations (ETL/data processing, media transcoding, ML inference, financial calc, web scraping). Duration is the key differentiator here, not just cost.

When recommending LMI, ALWAYS mention: minimum 3 execution environments for AZ resiliency (cannot go below 3 in production). GPU-accelerated functions default to a minimum of 1 instead (see gpu-acceleration.md).

Step 2: Build the Cost Comparison

REQUIRED: Present a cost comparison before recommending LMI.

Rule of thumb: LMI becomes cost-competitive at 50-100M+ req/month with steady traffic. Use the LMI Pricing Calculator for accurate comparisons.

Step 3: Configure the Deployment

Step 4: Migrate the Code

Review code for concurrency safety. LMI runs multiple invocations concurrently per execution environment:

Step 5: Set Up Infrastructure

  1. Create two IAM roles: execution role (for the function) and operator role (for capacity provider EC2 management)
  2. Configure VPC with subnets across 3+ AZs
  3. Create capacity provider with VPC config and scaling limits
  4. Create a new function with the capacity provider attached
  5. Publish a version (triggers instance provisioning)

Step 6: Validate and Cut Over

  1. Deploy to a non-production environment first
  2. Monitor CloudWatch: CPU utilization, memory, concurrency, throttle rate
  3. Gradual traffic shift at the invoking service or routing layer (10% → 50% → 100%)
  4. Compare costs after 1-2 weeks of production data
  5. Decommission the Lambda Event Function once stable

Best Practices

Pricing (always mention when discussing costs)

Scaling (always mention when discussing scaling or traffic)

Large container images (SOCI lazy loading)

Instance Sizing

Configuration

Migration

Operations

Long-duration invocations (asynchronous/ESM up to 90 min)

Long-running networking (functions now run for tens of minutes)

Limits Quick Reference

| Resource | Limit |

|----------|-------|

| Memory | 2 GB min, 32 GB max |

| Asynchronous/ESM invoke timeout | 90 min (5400s), via the existing Timeout field |

| Synchronous invoke timeout | Up to 30 min (1800s); Lambda stops synchronous invocations at 30 min even if Timeout is higher |

| Init phase | 15 min |

| ESM sources capped at 14 min | Amazon MQ, Amazon DocumentDB (other ESM sources get 90 min); see the event source mapping docs |

| Execution environments | 3 minimum (MinExecutionEnvironments, AZ resiliency); GPU-accelerated functions default to 1 |

| Instance lifespan | 14 days (auto-replaced) |

| Concurrency/vCPU | 64 (Node.js), 32 (Java/.NET), 16 (Python) |

| Runtimes | Node.js 22+, Java 21+, .NET 8+, Python 3.13+, Rust (provided.al2023) |

| Instance families | C, M, R (.large and up); NVIDIA GPU families for GPU-accelerated functions (see gpu-acceleration.md) |

| Scaling | Burst headroom equals unused capacity from TargetResourceUtilization; new instances launch within minutes |

| SOCI lazy loading | Container image functions on LMI only (not Lambda Event Functions on-demand); SOCI Index Manifest v2 only; image index with exactly one OCI image manifest plus the SOCI index (no multi-architecture indexes) |

Security Considerations

Files

| File | Content |

|------|---------|

| cost-comparison.md | Pricing analysis, break-even calculations, Savings Plans/RI impact |

| configuration-guide.md | Instance selection, memory ratios, scaling tuning, capacity provider config, SOCI lazy loading |

| thread-safety.md | Concurrency model per runtime, code review checklist, Powertools compatibility |

| migration-patterns.md | Before/after code by runtime, connection pooling, gradual cutover |

| infrastructure-setup.md | IAM roles, VPC setup, SAM templates, CLI commands |

| troubleshooting.md | Common errors, throttling, debugging, stuck deployments |

| gpu-acceleration.md | GPU setup rules, accelerator memory, GPU concurrency, startup, deployments, GPU errors |

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.