Skip to content

Commit bd3733c

Browse files
authored
Merge branch 'main' into feat/dsql-system-diagnostics
2 parents 23e6908 + 23dc619 commit bd3733c

15 files changed

Lines changed: 373 additions & 79 deletions

File tree

.claude-plugin/marketplace.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
"microvms",
8787
"firecracker"
8888
],
89-
"version": "1.2.0"
89+
"version": "1.3.0"
9090
},
9191
{
9292
"category": "migration",
@@ -118,7 +118,7 @@
118118
"name": "aws-transform",
119119
"source": "./plugins/aws-transform",
120120
"tags": ["aws", "migration", "modernization", "transform", "continuous modernization"],
121-
"version": "1.1.2"
121+
"version": "1.2.0"
122122
},
123123
{
124124
"category": "development",

plugins/aws-serverless/.claude-plugin/plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@
2222
"license": "Apache-2.0",
2323
"name": "aws-serverless",
2424
"repository": "https://github.com/awslabs/agent-plugins",
25-
"version": "1.2.0"
25+
"version": "1.3.0"
2626
}

plugins/aws-serverless/.codex-plugin/plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aws-serverless",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"description": "Design, build, deploy, test, and debug serverless applications with AWS Serverless services.",
55
"author": {
66
"name": "Amazon Web Services",

plugins/aws-serverless/skills/aws-lambda-managed-instances/SKILL.md

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ description: >
44
Evaluate, configure, and migrate workloads to AWS Lambda Managed Instances (LMI).
55
Triggers on: Lambda Managed Instances, LMI, capacity provider, multi-concurrency Lambda,
66
dedicated instance Lambda, EC2-backed Lambda, cold start elimination, Graviton Lambda,
7-
instance type for Lambda, Lambda cost optimization with Reserved Instances or Savings Plans.
8-
Also trigger when users describe high-volume predictable workloads seeking cost savings,
7+
instance type for Lambda, scheduled scaling for LMI, Lambda cost optimization with
8+
Reserved Instances or Savings Plans. Also trigger when users describe high-volume
9+
predictable workloads seeking cost savings, want to scale LMI capacity on a schedule,
910
or compare Lambda vs EC2 for steady-state traffic. For standard Lambda without LMI,
1011
use the aws-lambda skill instead.
1112
argument-hint: "[describe your workload or what you need help with]"
1213
metadata:
13-
tags: lambda, lmi, managed-instances, ec2, capacity-provider, multi-concurrency, cost-optimization
14+
tags: lambda, lmi, managed-instances, ec2, capacity-provider, multi-concurrency, cost-optimization, scheduled-scaling
1415
---
1516

1617
# AWS Lambda Managed Instances (LMI)
@@ -22,11 +23,11 @@ For standard Lambda development, see [aws-lambda skill](../aws-lambda/). For SAM
2223
## When to Load Reference Files
2324

2425
- **Cost comparison**, **pricing analysis**, **Lambda vs LMI cost**, **Savings Plans**, or **Reserved Instances** -> see [references/cost-comparison.md](references/cost-comparison.md)
25-
- **Instance types**, **memory sizing**, **vCPU ratios**, **scaling tuning**, or **capacity provider config** -> see [references/configuration-guide.md](references/configuration-guide.md)
26+
- **Instance types**, **memory sizing**, **vCPU ratios**, **scaling tuning**, **scheduled scaling**, or **capacity provider config** -> see [references/configuration-guide.md](references/configuration-guide.md)
2627
- **Thread safety**, **concurrency model**, **code review checklist**, **Powertools compatibility**, or **multi-concurrency readiness** -> see [references/thread-safety.md](references/thread-safety.md)
2728
- **Before/after code examples**, **runtime-specific migration** (Node.js, Python, Java, .NET), or **connection pooling** -> see [references/migration-patterns.md](references/migration-patterns.md)
28-
- **IAM roles**, **VPC setup**, **CLI commands**, **SAM template**, or **CDK example** -> see [references/infrastructure-setup.md](references/infrastructure-setup.md) and [scripts/setup-lmi.sh](scripts/setup-lmi.sh)
29-
- **Errors**, **throttling**, **debugging**, or **stuck deployments** -> see [references/troubleshooting.md](references/troubleshooting.md)
29+
- **IAM roles**, **VPC setup**, **CLI commands**, **SAM template**, **CDK example**, or **scheduled scaling setup (EventBridge Scheduler)** -> see [references/infrastructure-setup.md](references/infrastructure-setup.md) and [scripts/setup-lmi.sh](scripts/setup-lmi.sh)
30+
- **Errors**, **throttling**, **debugging**, **stuck deployments**, **tuning configuration**, or **adjusting after deployment** -> see [references/troubleshooting.md](references/troubleshooting.md)
3031

3132
## Quick Decision: Is LMI Right for This Workload?
3233

@@ -54,6 +55,38 @@ Gather these signals before recommending:
5455
6. **Concurrency readiness**: Thread safety (Node.js/Java/.NET)? Shared `/tmp` paths? Per-invocation DB connections?
5556
7. **VPC**: Already in a VPC? Private resource access needed?
5657

58+
#### Deriving LMI Configuration from Metrics
59+
60+
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.
61+
62+
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](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Lambda-Insights-extension-versions.html) and attach the `CloudWatchLambdaInsightsExecutionRolePolicy` managed policy to the function's execution role.
63+
64+
**Target max concurrency** (from `cpu_total_time` and `Duration`):
65+
66+
```
67+
PerExecutionEnvironmentMaxConcurrency = floor((0.5 × Duration) / cpu_total_time)
68+
```
69+
70+
This targets 50% CPU utilization at full concurrency, leaving headroom for scaling.
71+
72+
**Memory allocation** (from `memory_utilization` and current memory):
73+
74+
```
75+
MemorySize = min(32768, max(2048, MaxConcurrency × (memory_utilization / 100) × current_allocated_memory))
76+
```
77+
78+
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.
79+
80+
**Minimum execution environments** (from baseline `ConcurrentExecutions`):
81+
82+
```
83+
MinExecutionEnvironments = max(3, ceil(baseline_concurrent_executions × 2 / MaxConcurrency))
84+
```
85+
86+
Targets 50% concurrency utilization to leave headroom for traffic bursts.
87+
88+
**Without Lambda Insights:** Start with the runtime's default max concurrency, 2 GB memory, and MinExecutionEnvironments = 3. Adjust during testing.
89+
5790
### Step 2: Build the Cost Comparison
5891

5992
REQUIRED: Present a cost comparison before recommending LMI. Compare at minimum:
@@ -71,12 +104,14 @@ For discount analysis (Savings Plans, Reserved Instances), refer users to the [A
71104

72105
**Instance families** (~450 types): C-series (compute, .xlarge+), M-series (general, .large+), R-series (memory, .large+). ARM (Graviton) for best price-performance.
73106

74-
**Memory-to-vCPU ratios**: 2:1 (compute), 4:1 (general, default), 8:1 (memory). Min 2 GB, max 32 GB.
107+
**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.
75108

76109
**Multi-concurrency defaults/vCPU**: Node.js 64, Java 32, .NET 32, Python 16.
77110

78111
**Scaling**: MinExecutionEnvironments (default 3), MaxVCpuCount (default 400), TargetResourceUtilization.
79112

113+
**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.
114+
80115
See [references/configuration-guide.md](references/configuration-guide.md) for decision trees and detailed tuning.
81116

82117
### Step 4: Migrate the Code
@@ -105,16 +140,16 @@ See [references/infrastructure-setup.md](references/infrastructure-setup.md) for
105140
### Step 6: Validate and Cut Over
106141

107142
1. Deploy to a non-production environment first
108-
2. Monitor CloudWatch: CPU utilization, memory, concurrency, throttle rate
109-
3. Gradual traffic shift with weighted aliases (10% → 50% → 100%)
143+
2. Monitor CloudWatch: CPU utilization, memory, concurrency, throttle rate. If you observe low CPU utilization or ongoing throttles, see [references/troubleshooting.md](references/troubleshooting.md) for metric-specific adjustment guidance.
144+
3. Shift traffic to the LMI function (note: weighted alias shifting between LMI and non-LMI functions is not currently supported)
110145
4. Compare costs after 1-2 weeks of production data
111146
5. Decommission standard Lambda once stable
112147

113148
## Best Practices
114149

115150
### Configuration
116151

117-
- Do: Start with 4:1 ratio and runtime default concurrency
152+
- Do: Start with 2:1 ratio and runtime default concurrency
118153
- Do: Use ARM (Graviton) unless x86 dependencies exist
119154
- Do: Let Lambda choose instance types unless specific hardware needed
120155
- Do: Set MaxVCpuCount to control cost ceiling
@@ -125,7 +160,7 @@ See [references/infrastructure-setup.md](references/infrastructure-setup.md) for
125160

126161
- Do: Start with I/O-heavy functions (benefit most from multi-concurrency; CPU-bound functions compete for same CPU)
127162
- Do: Review code for concurrency safety before attaching to capacity provider (thread safety for Node.js/Java/.NET; `/tmp` and memory for Python)
128-
- Do: Use weighted aliases for gradual traffic shift
163+
- Do: Plan traffic shifting strategy based on your invocation source (weighted alias shifting between LMI and non-LMI functions is not currently supported)
129164
- Do: Include request IDs in all log statements
130165
- Do: Initialize DB pools and SDK clients outside the handler
131166
- Do: Estimate total `/tmp` usage under max concurrency
@@ -135,8 +170,10 @@ See [references/infrastructure-setup.md](references/infrastructure-setup.md) for
135170
### Operations
136171

137172
- Do: Set CloudWatch alarms on throttle rate > 1% and CPU > 80%
173+
- Do: Use scheduled scaling (EventBridge Scheduler) for predictable traffic — raise Min/Max before peak periods and lower them (or scale to zero) when idle
138174
- Don't: Manually terminate LMI EC2 instances (delete the capacity provider instead)
139175
- Don't: Forget to publish a version — unpublished functions cannot run on LMI
176+
- Don't: Rely on a deactivated (Min=Max=0) function to self-recover — schedule an explicit scale-up to reactivate it
140177

141178
## Limits Quick Reference
142179

@@ -172,7 +209,7 @@ REQUIRED: AWS credentials configured on the host machine.
172209

173210
### Regional Availability
174211

175-
Currently available: us-east-1, us-east-2, us-west-2, ap-northeast-1, eu-west-1. Expanding to all commercial regions soon.
212+
Available in all commercial AWS Regions except Israel (Tel Aviv), Middle East (Bahrain), Middle East (UAE), and Asia Pacific (Auckland).
176213

177214
Check the [Lambda Managed Instances documentation](https://docs.aws.amazon.com/lambda/latest/dg/lambda-managed-instances.html) for the latest regional availability.
178215

@@ -204,12 +241,14 @@ Override: "use SAM" → SAM YAML, "use CloudFormation" → CloudFormation YAML.
204241

205242
### Unsupported Region
206243

207-
- State: "Lambda Managed Instances is not yet available in [region]"
208-
- List available regions
244+
- State: "Lambda Managed Instances is not available in [region]"
245+
- Name the excluded regions: Israel (Tel Aviv), Middle East (Bahrain), Middle East (UAE), Asia Pacific (Auckland)
246+
- Suggest the nearest supported region
209247

210248
## Resources
211249

212250
- [Lambda Managed Instances Docs](https://docs.aws.amazon.com/lambda/latest/dg/lambda-managed-instances.html)
251+
- [Scaling LMI & Scheduled Scaling Docs](https://docs.aws.amazon.com/lambda/latest/dg/lambda-managed-instances-scaling.html)
213252
- [Introducing LMI (AWS Blog)](https://aws.amazon.com/blogs/aws/introducing-aws-lambda-managed-instances-serverless-simplicity-with-ec2-flexibility/)
214253
- [Build High-Performance Apps with LMI](https://aws.amazon.com/blogs/compute/build-high-performance-apps-with-aws-lambda-managed-instances/)
215254
- [Migrating Functions to LMI (AWS Blog)](https://aws.amazon.com/blogs/compute/migrating-your-functions-to-aws-lambda-managed-instances/)

plugins/aws-serverless/skills/aws-lambda-managed-instances/references/configuration-guide.md

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
- **CPU-intensive** (encoding, ML, compression) → C-series, 2:1 ratio, concurrency=1/vCPU
66
- **Memory-intensive** (caching, large datasets) → R-series, 8:1 ratio
77
- **Network-intensive** (streaming, data transfer) → Use AllowedInstanceTypes for n-suffix types, 4:1 ratio
8-
- **General/balanced** (web APIs, microservices) → M-series, 4:1 ratio, default concurrency
8+
- **General/balanced** (web APIs, microservices) → M-series, 2:1 ratio (default), default concurrency
99

1010
Architecture: ARM (Graviton, g-suffix) for price-performance. x86 (i=Intel, a=AMD) when dependencies require it.
1111

1212
## Memory-to-vCPU Ratios
1313

14-
| Ratio | Profile | When to use | Memory examples |
15-
| ----- | ------- | -------------------------- | --------------------- |
16-
| 2:1 | Compute | CPU-bound work | 2GB/1vCPU, 4GB/2vCPU |
17-
| 4:1 | General | Most workloads (default) | 4GB/1vCPU, 8GB/2vCPU |
18-
| 8:1 | Memory | Caching, data, Python apps | 8GB/1vCPU, 16GB/2vCPU |
14+
| Ratio | Profile | When to use | Memory examples |
15+
| ----- | ------- | -------------------------------- | --------------------- |
16+
| 2:1 | Compute | CPU-bound work (default) | 2GB/1vCPU, 4GB/2vCPU |
17+
| 4:1 | General | Mixed CPU/memory-heavy workloads | 4GB/1vCPU, 8GB/2vCPU |
18+
| 8:1 | Memory | Memory-heavy or Python apps | 8GB/1vCPU, 16GB/2vCPU |
1919

2020
Min: 2 GB / 1 vCPU. Max: 32 GB. Memory must align with ratio multiples.
2121

@@ -51,6 +51,26 @@ Total capacity = MinExecutionEnvironments × PerExecutionEnvironmentMaxConcurren
5151
| AllowedInstanceTypes | All | Restrict only for specific hardware needs |
5252
| ExcludedInstanceTypes | None | Exclude expensive types in dev/test |
5353

54+
## Scheduled Scaling (Predictable Traffic)
55+
56+
For workloads with known traffic patterns (business hours, marketing events, batch windows), use [Amazon EventBridge Scheduler](https://docs.aws.amazon.com/scheduler/latest/UserGuide/managing-targets-universal.html) to adjust a function's `MinExecutionEnvironments` and `MaxExecutionEnvironments` on a one-time or recurring schedule. A schedule (cron or rate expression) targets the Lambda `PutFunctionScalingConfig` API as an EventBridge Scheduler universal target, passing new Min/Max values in the input payload.
57+
58+
**Behavior:**
59+
60+
- Scheduled scaling sets the provisioned floor and ceiling. Actual scaling between Min and Max still responds to CPU utilization and concurrency saturation.
61+
- If traffic more than doubles within 5 minutes of a scheduled scale-up, you may still see throttles while capacity provisions.
62+
- Setting both `MinExecutionEnvironments` and `MaxExecutionEnvironments` to 0 deactivates the function version (instances terminate). A deactivated function does NOT auto-recover — schedule a separate action with non-zero values to reactivate it.
63+
64+
**Common patterns:**
65+
66+
| Pattern | Scale-up schedule | Scale-down schedule |
67+
| ---------------------- | ----------------------------------- | -------------------------------- |
68+
| Business hours | Raise Min/Max before work starts | Lower Min/Max after hours |
69+
| Marketing/launch event | Raise Min ahead of the campaign | Restore baseline after the event |
70+
| Idle scale-to-zero | Reactivate (non-zero) before demand | Set Min=Max=0 when idle |
71+
72+
See [infrastructure-setup.md](infrastructure-setup.md) for the EventBridge Scheduler IAM role and `create-schedule` CLI examples.
73+
5474
## Monitoring Thresholds
5575

5676
- **CPU > 80%**: reduce concurrency or add vCPUs

plugins/aws-serverless/skills/aws-lambda-managed-instances/references/infrastructure-setup.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,83 @@ Resources:
224224
CapacityProviderArn: !GetAtt MyCP.Arn
225225
```
226226
227+
## Scheduled Scaling (EventBridge Scheduler)
228+
229+
For predictable traffic, adjust `MinExecutionEnvironments`/`MaxExecutionEnvironments` on a schedule using [Amazon EventBridge Scheduler](https://docs.aws.amazon.com/scheduler/latest/UserGuide/managing-targets-universal.html). The schedule calls the Lambda `PutFunctionScalingConfig` API directly as a universal target — no Lambda code or extra glue required.
230+
231+
### 1. Scheduler execution role
232+
233+
Trust policy (allow EventBridge Scheduler to assume the role):
234+
235+
```json
236+
{
237+
"Version": "2012-10-17",
238+
"Statement": [{
239+
"Effect": "Allow",
240+
"Principal": { "Service": "scheduler.amazonaws.com" },
241+
"Action": "sts:AssumeRole"
242+
}]
243+
}
244+
```
245+
246+
Permissions (call `PutFunctionScalingConfig` on the target function):
247+
248+
```json
249+
{
250+
"Version": "2012-10-17",
251+
"Statement": [{
252+
"Effect": "Allow",
253+
"Action": "lambda:PutFunctionScalingConfig",
254+
"Resource": "arn:aws:lambda:*:*:function:my-lmi-function"
255+
}]
256+
}
257+
```
258+
259+
### 2. Create schedules
260+
261+
Scale up before peak (08:00 UTC daily):
262+
263+
```bash
264+
aws scheduler create-schedule \
265+
--name ScaleUpLmi \
266+
--schedule-expression "cron(0 8 * * ? *)" \
267+
--flexible-time-window '{"Mode": "OFF"}' \
268+
--target '{
269+
"Arn": "arn:aws:scheduler:::aws-sdk:lambda:PutFunctionScalingConfig",
270+
"RoleArn": "arn:aws:iam::<account-id>:role/eventbridge-scheduler-role",
271+
"Input": "{\"FunctionName\": \"my-lmi-function\", \"Qualifier\": \"$LATEST.PUBLISHED\", \"FunctionScalingConfig\": {\"MinExecutionEnvironments\": 100, \"MaxExecutionEnvironments\": 1000}}"
272+
}'
273+
```
274+
275+
Scale down after peak (18:00 UTC daily):
276+
277+
```bash
278+
aws scheduler create-schedule \
279+
--name ScaleDownLmi \
280+
--schedule-expression "cron(0 18 * * ? *)" \
281+
--flexible-time-window '{"Mode": "OFF"}' \
282+
--target '{
283+
"Arn": "arn:aws:scheduler:::aws-sdk:lambda:PutFunctionScalingConfig",
284+
"RoleArn": "arn:aws:iam::<account-id>:role/eventbridge-scheduler-role",
285+
"Input": "{\"FunctionName\": \"my-lmi-function\", \"Qualifier\": \"$LATEST.PUBLISHED\", \"FunctionScalingConfig\": {\"MinExecutionEnvironments\": 5, \"MaxExecutionEnvironments\": 20}}"
286+
}'
287+
```
288+
289+
Set both values to `0` to deactivate during idle periods; schedule a separate non-zero action to reactivate (a deactivated function does not auto-recover).
290+
291+
### Manual override
292+
293+
Update scaling limits directly at any time:
294+
295+
```bash
296+
aws lambda put-function-scaling-config \
297+
--function-name my-lmi-function \
298+
--qualifier '$LATEST.PUBLISHED' \
299+
--function-scaling-config MinExecutionEnvironments=5,MaxExecutionEnvironments=20
300+
```
301+
302+
`MinExecutionEnvironments` and `MaxExecutionEnvironments` accept values from 0 to 15000 and must be set together. Setting them on `$LATEST.PUBLISHED` propagates to future published versions.
303+
227304
## Cleanup
228305

229306
```bash

plugins/aws-serverless/skills/aws-lambda-managed-instances/references/troubleshooting.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,41 @@
11
# LMI Troubleshooting
22

3+
## Testing Phase: Monitor and Adjust
4+
5+
After deploying your LMI function with a test workload, check these metrics and adjust:
6+
7+
**Duration increased vs. existing function:**
8+
9+
- This indicates the concurrency estimations used during setup may be off. Investigate by:
10+
- Checking ExecutionEnvironmentCPUUtilization and ExecutionEnvironmentMemoryUtilization for saturation
11+
- Reducing PerExecutionEnvironmentMaxConcurrency to see if duration improves
12+
- Reviewing instance types — switching to larger or more powerful instances may help if resources are constrained
13+
- If reducing concurrency doesn't help, check throttle metrics below
14+
15+
**Low ExecutionEnvironmentCPUUtilization (below 10%):**
16+
17+
- Increase PerExecutionEnvironmentMaxConcurrency to improve utilization
18+
- Or lower MemorySize to reduce vCPUs per execution environment
19+
- If memory utilization is also high, increase ExecutionEnvironmentMemoryGiBPerVCpu ratio instead
20+
21+
**Ongoing CPUThrottles:**
22+
23+
- Switch capacity provider to Manual scaling mode with a lower CPU utilization target (e.g., 25%)
24+
25+
**Ongoing MemoryThrottles:**
26+
27+
- Increase MemorySize
28+
- To maintain the same vCPU count, adjust ratio proportionally (e.g., 4GB/2:1 → 8GB/4:1 keeps 2 vCPUs)
29+
30+
**Ongoing DiskThrottles:**
31+
32+
- Reduce per-invocation /tmp usage or reduce PerExecutionEnvironmentMaxConcurrency
33+
34+
**Ongoing ConcurrencyThrottles:**
35+
36+
- Increase PerExecutionEnvironmentMaxConcurrency (if CPU and memory have headroom)
37+
- Check if MaxExecutionEnvironments or MaxVCpuCount is capping scale-out
38+
339
## Common Issues
440

541
| Issue | Cause | Resolution |

plugins/aws-transform/.claude-plugin/plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
"license": "Apache-2.0",
3232
"name": "aws-transform",
3333
"repository": "https://github.com/awslabs/agent-plugins",
34-
"version": "1.1.2"
34+
"version": "1.2.0"
3535
}

0 commit comments

Comments
 (0)