Skip to content

Commit 6a5c696

Browse files
gunnargroschbfreibergkrokoko
authored
feat(aws-serverless): add aws-serverless plugin (#52)
* feat(aws-serverless): add aws-serverless plugin with aws-lambda and aws-serverless-deployment skills Add the aws-serverless plugin with two new skills, MCP server configuration, SAM template validation hook, and marketplace entry. - aws-lambda: Lambda runtime behavior, event sources, EventBridge, Step Functions, orchestration, observability, optimization, and troubleshooting - aws-serverless-deployment: SAM and CDK project setup, CDK constructs and patterns, CI/CD pipelines, and SAM/CDK coexistence Also adds the aws-serverless MCP server (.mcp.json), a SAM template validation hook, and updates the marketplace registry. Based on https://github.com/gunnargrosch/aws-serverless-plugin * feat(aws-serverless): add aws-lambda-durable-functions skill Add the aws-lambda-durable-functions skill to the aws-serverless plugin with getting started guide, checkpoint-replay model, testing guidance, advanced patterns, and error handling references. * addresses review feedback from reedham-aws - Remove sensitive data access flags from MCP server configuration - Add --lint flag to SAM template validation for stricter checks - Update validation messages to reflect linting improvements - Reorganize SKILL.md with clearer onboarding steps and prerequisites - Refine skill description to focus on core capabilities - Add advanced-error-handling.md reference guide for timeout and circuit breaker patterns - Update reference file routing to include advanced error handling scenarios - Consolidate guidelines into onboarding section for better user flow - Improve documentation structure for better discoverability * docs(aws-serverless): Reorganize Lambda references and update runtime requirements - Split Powertools documentation into dedicated reference file (powertools.md) - Update SKILL.md routing to direct Powertools queries to new dedicated reference - Update observability.md link to point to powertools.md instead of optimization.md - Clarify Python runtime requirements for durable functions (3.11+ minimum, 3.13+ for Lambda pre-installed SDK) * Fix formatting * docs(aws-serverless): Reorganize documentation and update plugin version - Move troubleshooting production executions content to dedicated troubleshooting-executions.md reference file - Set language and IaC framework defaults including override syntax - Add error scenario handling for unsupported languages and frameworks - Remove inline troubleshooting agent instructions from main SKILL.md for better modularity - Consolidate advanced error handling references to separate advanced-error-handling.md file - Update plugin version from 1.1.0 to 1.0.0 * Split Step Functions testing into own file * docs(aws-serverless): Update CODEOWNERS, README and align Lambda skills - Add aws-serverless plugin to CODEOWNERS with appropriate team assignments - Add aws-serverless plugin to main README.md plugin table with feature description - Simplify AWS CLI setup instructions and remove redundant steps - Separate SAM CLI and container runtime setup into distinct sections - Update container runtime documentation to mention alternatives - Clarify MCP server default security posture and flag requirements in Lambda skill * docs(aws-serverless): Add sam local start-api references to Lambda and SAM guides * Switch to allow-write by default and add jq check * docs(aws-serverless): Fix review comments - Fix IAM permission name from `CheckpointDurableExecutions` to `CheckpointDurableExecution` - Update MCP server configuration flag from `--allow write` to `--allow-write` for consistency - Increase validation script timeout from 30s to 120s and MCP server timeout to 120000ms - Add jq dependency check to validate-template.sh with graceful fallback message - Improve SAM CLI validation error handling with fallback JSON formatting - Add circuit breaker replay model caveat to advanced error handling documentation - Fix CloudFormation reference from `DurableFunctionAlias` to `DurableFunction.Alias` - Add Step Functions testing reference to Lambda skill navigation guide - Enhance error messages for missing dependencies and validation failures * docs(aws-serverless): Remove PostToolUse hooks and update Docker verification - Remove PostToolUse hooks from aws-lambda-durable-functions SKILL.md that provided replay model reminders - Update getting-started.md to remove hardcoded docker --version check - Replace Docker requirement with flexible container runtime verification (Docker, Finch, Podman, etc.) - Simplify credential setup instructions to be more concise * docs(aws-serverless): Update documentation and formatting - Condense advanced error handling patterns with concise implementation approaches - Streamline advanced patterns documentation with focused guidance - Simplify error handling reference with key considerations - Update step operations documentation for clarity - Refactor testing patterns reference for better readability - Consolidate troubleshooting executions guide - Simplify wait operations documentation - Update orchestration and workflows reference in main Lambda skill - Remove verbose code examples in favor of pattern descriptions and implementation approaches - Normalize marketplace tags from hyphenated to space-separated format - Fix heading hierarchy in durable functions SKILL.md - Reorder CODEOWNERS entries alphabetically - Update Python code examples with proper imports and corrected API usage patterns - Improve code consistency and readability across durable functions documentation * docs(aws-serverless): Add Python API differences and fix testing patterns - Fix error property reference in testing-patterns.md from `getError()?.message` to `getError()?.errorMessage` - Update aws-serverless-deployment description to include "use SAM" trigger phrase - Clarify Python SDK differences from TypeScript for durable functions implementation --------- Signed-off-by: Alain Krok <alkrok@amazon.com> Co-authored-by: Ben Freiberg <9841563+bfreiberg@users.noreply.github.com> Co-authored-by: Alain Krok <alkrok@amazon.com>
1 parent 2adc93c commit 6a5c696

37 files changed

Lines changed: 8865 additions & 0 deletions

.claude-plugin/marketplace.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,37 @@
4747
"source": "./plugins/amazon-location-service",
4848
"tags": ["aws", "location", "maps", "geospatial"],
4949
"version": "1.0.0"
50+
},
51+
{
52+
"category": "development",
53+
"description": "Design, build, deploy, test, and debug serverless applications with AWS Serverless services.",
54+
"keywords": [
55+
"aws",
56+
"aws agent skills",
57+
"amazon",
58+
"serverless",
59+
"lambda",
60+
"durable functions",
61+
"development",
62+
"sam",
63+
"api gateway",
64+
"eventbridge",
65+
"step functions"
66+
],
67+
"name": "aws-serverless",
68+
"source": "./plugins/aws-serverless",
69+
"tags": [
70+
"aws",
71+
"serverless",
72+
"lambda",
73+
"durable functions",
74+
"development",
75+
"sam",
76+
"api gateway",
77+
"eventbridge",
78+
"step functions"
79+
],
80+
"version": "1.0.0"
5081
}
5182
]
5283
}

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ tools/ @awslabs/agent-plugins-admins
3131
## Plugins (alphabetically listed)
3232

3333
plugins/amazon-location-service @awslabs/agent-plugins-admins @awslabs/agent-plugins-maintainers @awslabs/agent-plugins-agent-plugins-amazon-location-service
34+
plugins/aws-serverless @awslabs/agent-plugins-admins @awslabs/agent-plugins-maintainers @awslabs/agent-plugins-aws-serverless
3435
plugins/deploy-on-aws @awslabs/agent-plugins-admins @awslabs/agent-plugins-maintainers @awslabs/agent-plugins-deploy-on-aws
3536

3637
## File must end with CODEOWNERS file

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ To maximize the benefits of plugin-assisted development while maintaining securi
3030
| --------------------------- | ----------------------------------------------------------------------------------------------------------------- | --------- |
3131
| **deploy-on-aws** | Deploy applications to AWS with architecture recommendations, cost estimates, and IaC deployment | Available |
3232
| **amazon-location-service** | Add maps, geocoding, routing, places search, and geospatial features to applications with Amazon Location Service | Available |
33+
| **aws-serverless** | Build serverless applications with Lambda, API Gateway, EventBridge, Step Functions, and durable functions | Available |
3334

3435
## Installation
3536

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"author": {
3+
"name": "Amazon Web Services"
4+
},
5+
"description": "Design, build, deploy, test, and debug serverless applications with AWS Serverless services.",
6+
"homepage": "https://github.com/awslabs/agent-plugins",
7+
"keywords": [
8+
"aws",
9+
"lambda",
10+
"durable functions",
11+
"serverless",
12+
"development",
13+
"sam",
14+
"api-gateway",
15+
"eventbridge",
16+
"step-functions"
17+
],
18+
"license": "Apache-2.0",
19+
"name": "aws-serverless",
20+
"repository": "https://github.com/awslabs/agent-plugins",
21+
"version": "1.0.0"
22+
}

plugins/aws-serverless/.mcp.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"mcpServers": {
3+
"aws-serverless-mcp": {
4+
"command": "uvx",
5+
"args": [
6+
"awslabs.aws-serverless-mcp-server@latest",
7+
"--allow-write"
8+
],
9+
"env": {
10+
"FASTMCP_LOG_LEVEL": "ERROR"
11+
},
12+
"timeout": 120000
13+
}
14+
}
15+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"hooks": {
3+
"PostToolUse": [
4+
{
5+
"matcher": "Edit|Write",
6+
"hooks": [
7+
{
8+
"type": "command",
9+
"command": "${CLAUDE_PLUGIN_ROOT}/scripts/validate-template.sh",
10+
"timeout": 120
11+
}
12+
]
13+
}
14+
]
15+
}
16+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
# Validates SAM templates after editing template.yaml or template.yml.
3+
# Runs as a PostToolUse hook on Edit/Write operations.
4+
5+
set -euo pipefail
6+
7+
# Skip if jq is not installed
8+
if ! command -v jq &> /dev/null; then
9+
echo '{"systemMessage": "jq not found — SAM template validation skipped. Install jq for automatic validation."}'
10+
exit 0
11+
fi
12+
13+
INPUT=$(cat)
14+
15+
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // empty')
16+
17+
# Only validate SAM template files
18+
case "$FILE_PATH" in
19+
*template.yaml|*template.yml) ;;
20+
*) exit 0 ;;
21+
esac
22+
23+
# Skip if SAM CLI is not installed
24+
if ! command -v sam &> /dev/null; then
25+
echo '{"systemMessage": "SAM CLI not found — template validation skipped. Install SAM CLI for automatic validation."}'
26+
exit 0
27+
fi
28+
29+
# Skip if file doesn't exist (deleted)
30+
if [ ! -f "$FILE_PATH" ]; then
31+
exit 0
32+
fi
33+
34+
OUTPUT=$(sam validate --template "$FILE_PATH" --lint 2>&1) && STATUS=0 || STATUS=$?
35+
36+
if [ $STATUS -eq 0 ]; then
37+
echo '{"systemMessage": "SAM template validation and linting passed."}'
38+
else
39+
FORMATTED=$(echo "$OUTPUT" | jq -Rs '{systemMessage: ("SAM template validation/linting failed:\n" + .)}' 2>/dev/null) || \
40+
FORMATTED="{\"systemMessage\": \"SAM template validation/linting failed:\\n$OUTPUT\"}"
41+
echo "$FORMATTED"
42+
fi
43+
44+
exit 0
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
---
2+
name: aws-lambda-durable-functions
3+
description: >
4+
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 with LocalDurableTestRunner. Triggers on phrases like: lambda durable functions, workflow orchestration, state machines, retry/checkpoint patterns, long-running stateful Lambda functions, saga pattern, human-in-the-loop callbacks, and reliable serverless applications.
5+
---
6+
7+
# AWS Lambda durable functions
8+
9+
Build resilient multi-step applications and AI workflows that can execute for up to 1 year while maintaining reliable progress despite interruptions.
10+
11+
## Onboarding
12+
13+
### Step 1: Validate Prerequisites
14+
15+
Before using AWS Lambda durable functions, verify:
16+
17+
1. **AWS CLI** is installed (2.33.22 or higher) and configured:
18+
19+
```bash
20+
aws --version
21+
aws sts get-caller-identity
22+
```
23+
24+
2. **Runtime environment** is ready:
25+
- For TypeScript/JavaScript: Node.js 22+ (`node --version`)
26+
- For Python: Python 3.11+ (`python --version`. Note that currently only Lambda runtime environments 3.13+ come with the Durable Execution SDK pre-installed. 3.11 is the min supported Python version by the Durable SDK itself, however, you could use OCI to bring your own container image with your own Python runtime + Durable SDK.)
27+
28+
3. **Deployment capability** exists (one of):
29+
- AWS SAM CLI (`sam --version`) 1.153.1 or higher
30+
- AWS CDK (`cdk --version`) v2.237.1 or higher
31+
- Direct Lambda deployment access
32+
33+
### Step 2: Select language and IaC framework
34+
35+
### Language Selection
36+
37+
Default: TypeScript
38+
39+
Override syntax:
40+
41+
- "use Python" → Generate Python code
42+
- "use JavaScript" → Generate JavaScript code
43+
44+
When not specified, ALWAYS use TypeScript
45+
46+
### IaC framework selection
47+
48+
Default: CDK
49+
50+
Override syntax:
51+
52+
- "use CloudFormation" → Generate YAML templates
53+
- "use SAM" → Generate YAML templates
54+
55+
When not specified, ALWAYS use CDK
56+
57+
### Error Scenarios
58+
59+
#### Unsupported Language
60+
61+
- List detected language
62+
- State: "Durable Execution SDK is not yet available for [framework]"
63+
- Suggest supported languages as alternatives
64+
65+
#### Unsupported IaC Framework
66+
67+
- List detected framework
68+
- State: "[framework] might not support Lambda durable functions yet"
69+
- Suggest supported frameworks as alternatives
70+
71+
### Serverless MCP Server Unavailable
72+
73+
- Inform user: "AWS Serverless MCP not responding"
74+
- Ask: "Proceed without MCP support?"
75+
- DO NOT continue without user confirmation
76+
77+
### Step 3: Install SDK
78+
79+
**For TypeScript/JavaScript:**
80+
81+
```bash
82+
npm install @aws/durable-execution-sdk-js
83+
npm install --save-dev @aws/durable-execution-sdk-js-testing
84+
```
85+
86+
**For Python:**
87+
88+
```bash
89+
pip install aws-durable-execution-sdk-python
90+
pip install aws-durable-execution-sdk-python-testing
91+
```
92+
93+
## When to Load Reference Files
94+
95+
Load the appropriate reference file based on what the user is working on:
96+
97+
- **Getting started**, **basic setup**, **example**, **ESLint**, or **Jest setup** -> see [getting-started.md](references/getting-started.md)
98+
- **Understanding replay model**, **determinism**, or **non-deterministic errors** -> see [replay-model-rules.md](references/replay-model-rules.md)
99+
- **Creating steps**, **atomic operations**, or **retry logic** -> see [step-operations.md](references/step-operations.md)
100+
- **Waiting**, **delays**, **callbacks**, **external systems**, or **polling** -> see [wait-operations.md](references/wait-operations.md)
101+
- **Parallel execution**, **map operations**, **batch processing**, or **concurrency** -> see [concurrent-operations.md](references/concurrent-operations.md)
102+
- **Error handling**, **retry strategies**, **saga pattern**, or **compensating transactions** -> see [error-handling.md](references/error-handling.md)
103+
- **Advanced error handling**, **timeout handling**, **circuit breakers**, or **conditional retries** -> see [advanced-error-handling.md](references/advanced-error-handling.md)
104+
- **Testing**, **local testing**, **cloud testing**, **test runner**, or **flaky tests** -> see [testing-patterns.md](references/testing-patterns.md)
105+
- **Deployment**, **CloudFormation**, **CDK**, **SAM**, **log groups**, **deploy**, or **infrastructure** -> see [deployment-iac.md](references/deployment-iac.md)
106+
- **Advanced patterns**, **GenAI agents**, **completion policies**, **step semantics**, or **custom serialization** -> see [advanced-patterns.md](references/advanced-patterns.md)
107+
- **troubleshooting**, **stuck execution**, **failed execution**, **debug execution ID**, or **execution history** -> see [troubleshooting-executions.md](references/troubleshooting-executions.md)
108+
109+
## Quick Reference
110+
111+
### Basic Handler Pattern
112+
113+
**TypeScript:**
114+
115+
```typescript
116+
import { withDurableExecution, DurableContext } from '@aws/durable-execution-sdk-js';
117+
118+
export const handler = withDurableExecution(async (event, context: DurableContext) => {
119+
const result = await context.step('process', async () => processData(event));
120+
return result;
121+
});
122+
```
123+
124+
**Python:**
125+
126+
```python
127+
from aws_durable_execution_sdk_python import durable_execution, DurableContext
128+
129+
@durable_execution
130+
def handler(event: dict, context: DurableContext) -> dict:
131+
result = context.step(lambda _: process_data(event), name='process')
132+
return result
133+
```
134+
135+
### Critical Rules
136+
137+
1. **All non-deterministic code MUST be in steps** (Date.now, Math.random, API calls)
138+
2. **Cannot nest durable operations** - use `runInChildContext` to group operations
139+
3. **Closure mutations are lost on replay** - return values from steps
140+
4. **Side effects outside steps repeat** - use `context.logger` (replay-aware)
141+
142+
### Python API Differences
143+
144+
The Python SDK differs from TypeScript in several key areas:
145+
146+
- **Steps**: Use `@durable_step` decorator + `context.step(my_step(args))`, or inline `context.step(lambda _: ..., name='...')`. Prefer the decorator for automatic step naming.
147+
- **Wait**: `context.wait(duration=Duration.from_seconds(n), name='...')`
148+
- **Exceptions**: `ExecutionError` (permanent), `InvocationError` (transient), `CallbackError` (callback failures)
149+
- **Testing**: Use `DurableFunctionTestRunner` class directly - instantiate with handler, use context manager, call `run(input=...)`
150+
151+
### Invocation Requirements
152+
153+
Durable functions **require qualified ARNs** (version, alias, or `$LATEST`):
154+
155+
```bash
156+
# Valid
157+
aws lambda invoke --function-name my-function:1 output.json
158+
aws lambda invoke --function-name my-function:prod output.json
159+
160+
# Invalid - will fail
161+
aws lambda invoke --function-name my-function output.json
162+
```
163+
164+
## IAM Permissions
165+
166+
Your Lambda execution role MUST have the `AWSLambdaBasicDurableExecutionRolePolicy` managed policy attached. This includes:
167+
168+
- `lambda:CheckpointDurableExecution` - Persist execution state
169+
- `lambda:GetDurableExecutionState` - Retrieve execution state
170+
- CloudWatch Logs permissions
171+
172+
**Additional permissions needed for:**
173+
174+
- **Durable invokes**: `lambda:InvokeFunction` on target function ARNs
175+
- **External callbacks**: Systems need `lambda:SendDurableExecutionCallbackSuccess` and `lambda:SendDurableExecutionCallbackFailure`
176+
177+
## Validation Guidelines
178+
179+
When writing or reviewing durable function code, ALWAYS check for these replay model violations:
180+
181+
1. **Non-deterministic code outside steps**: `Date.now()`, `Math.random()`, UUID generation, API calls, database queries must all be inside steps
182+
2. **Nested durable operations in step functions**: Cannot call `context.step()`, `context.wait()`, or `context.invoke()` inside a step function — use `context.runInChildContext()` instead
183+
3. **Closure mutations that won't persist**: Variables mutated inside steps are NOT preserved across replays — return values from steps instead
184+
4. **Side effects outside steps that repeat on replay**: Use `context.logger` for logging (it is replay-aware and deduplicates automatically)
185+
186+
When implementing or modifying tests for durable functions, ALWAYS verify:
187+
188+
1. All operations have descriptive names
189+
2. Tests get operations by NAME, never by index
190+
3. Replay behavior is tested with multiple invocations
191+
4. Use `LocalDurableTestRunner` for local testing
192+
193+
### MCP Server Configuration
194+
195+
**Write access is enabled by default.** The plugin ships with `--allow-write` in `.mcp.json`, so the MCP server can create projects, generate IaC, and deploy on behalf of the user.
196+
197+
Access to sensitive data (like Lambda and API Gateway logs) is **not** enabled by default. To grant it, add `--allow-sensitive-data-access` to `.mcp.json`.
198+
199+
## Resources
200+
201+
- [AWS Lambda durable functions Documentation](https://docs.aws.amazon.com/lambda/latest/dg/durable-functions.html)
202+
- [JavaScript SDK Repository](https://github.com/aws/aws-durable-execution-sdk-js)
203+
- [Python SDK Repository](https://github.com/aws/aws-durable-execution-sdk-python)
204+
- [IAM Policy Reference](https://docs.aws.amazon.com/aws-managed-policy/latest/reference/AWSLambdaBasicDurableExecutionRolePolicy.html)

0 commit comments

Comments
 (0)