aws-serverless-eda by zxkane/aws-skills
npx skills add https://github.com/zxkane/aws-skills --skill aws-serverless-eda包含 Hooks
此技能使用 Claude hooks,它们可以自动执行代码以响应事件。安装前请仔细审查。
此技能基于 Well-Architected Framework 原则,为在 AWS 上构建无服务器应用程序和事件驱动架构提供全面指导。
在回答之前,务必使用 MCP 工具(mcp__aws-mcp__* 或 mcp__*awsdocs*__*)验证 AWS 事实。aws-mcp-setup 依赖项会自动加载——如果 MCP 工具不可用,请引导用户完成该技能的设置流程。
此技能利用 CDK MCP 服务器(通过 aws-cdk-development 依赖项提供)和 AWS 文档 MCP 来提供无服务器指导。
注意:以下 AWS MCP 服务器可通过完整的 AWS MCP 服务器单独获取(参见
aws-mcp-setup技能),不与此插件捆绑提供:
- AWS Serverless MCP — SAM CLI 生命周期(初始化、部署、本地测试)
- AWS Lambda Tool MCP — 直接 Lambda 调用
- AWS Step Functions MCP — 工作流编排
- Amazon SNS/SQS MCP — 消息传递和队列管理
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
在以下情况下使用此技能:
函数应简洁且单一用途
// ✅ 良好 - 单一用途、专注的函数
export const processOrder = async (event: OrderEvent) => {
// 仅处理订单处理
const order = await validateOrder(event);
await saveOrder(order);
await publishOrderCreatedEvent(order);
return { statusCode: 200, body: JSON.stringify({ orderId: order.id }) };
};
// ❌ 不佳 - 函数做太多事情
export const handleEverything = async (event: any) => {
// 处理订单、库存、支付、运输...
// 职责过多
};
保持函数环境高效且成本意识:
为并发而非总量设计
Lambda 水平扩展 - 设计考虑应侧重于:
// 考虑并发 Lambda 执行访问 DynamoDB
const table = new dynamodb.Table(this, 'Table', {
billingMode: dynamodb.BillingMode.PAY_PER_REQUEST, // 随负载自动扩展
});
// 或者使用预置容量 + 自动扩展
const table = new dynamodb.Table(this, 'Table', {
billingMode: dynamodb.BillingMode.PROVISIONED,
readCapacity: 5,
writeCapacity: 5,
});
// 为并发负载启用自动扩展
table.autoScaleReadCapacity({ minCapacity: 5, maxCapacity: 100 });
table.autoScaleWriteCapacity({ minCapacity: 5, maxCapacity: 100 });
函数运行时环境是短暂的
// ❌ 不佳 - 依赖本地文件系统
export const handler = async (event: any) => {
fs.writeFileSync('/tmp/data.json', JSON.stringify(data)); // 执行后丢失
};
// ✅ 良好 - 使用持久化存储
export const handler = async (event: any) => {
await s3.putObject({
Bucket: process.env.BUCKET_NAME,
Key: 'data.json',
Body: JSON.stringify(data),
});
};
状态管理:
应用程序必须与硬件无关
基础设施可能随时更改:
为可移植性设计:
使用 Step Functions 进行编排
// ❌ 不佳 - Lambda 函数链式调用
export const handler1 = async (event: any) => {
const result = await processStep1(event);
await lambda.invoke({
FunctionName: 'handler2',
Payload: JSON.stringify(result),
});
};
// ✅ 良好 - Step Functions 编排
const stateMachine = new stepfunctions.StateMachine(this, 'OrderWorkflow', {
definition: stepfunctions.Chain
.start(validateOrder)
.next(processPayment)
.next(shipOrder)
.next(sendConfirmation),
});
Step Functions 的优势:
事件驱动优于同步请求/响应
// 模式:事件驱动处理
const bucket = new s3.Bucket(this, 'DataBucket');
bucket.addEventNotification(
s3.EventType.OBJECT_CREATED,
new s3n.LambdaDestination(processFunction),
{ prefix: 'uploads/' }
);
// 模式:EventBridge 集成
const rule = new events.Rule(this, 'OrderRule', {
eventPattern: {
source: ['orders'],
detailType: ['OrderPlaced'],
},
});
rule.addTarget(new targets.LambdaFunction(processOrderFunction));
优势:
操作必须是幂等的
// ✅ 良好 - 幂等操作
export const handler = async (event: SQSEvent) => {
for (const record of event.Records) {
const orderId = JSON.parse(record.body).orderId;
// 检查是否已处理(幂等性)
const existing = await dynamodb.getItem({
TableName: process.env.TABLE_NAME,
Key: { orderId },
});
if (existing.Item) {
console.log('订单已处理:', orderId);
continue; // 跳过重复项
}
// 处理订单
await processOrder(orderId);
// 标记为已处理
await dynamodb.putItem({
TableName: process.env.TABLE_NAME,
Item: { orderId, processedAt: Date.now() },
});
}
};
使用指数退避实现重试逻辑:
async function withRetry<T>(fn: () => Promise<T>, maxRetries = 3): Promise<T> {
for (let i = 0; i < maxRetries; i++) {
try {
return await fn();
} catch (error) {
if (i === maxRetries - 1) throw error;
await new Promise(resolve => setTimeout(resolve, Math.pow(2, i) * 1000));
}
}
throw new Error('超出最大重试次数');
}
有关完整代码示例的详细实现模式,请参阅参考文档:
文件:references/eda-patterns.md
文件:references/serverless-patterns.md
重要提示:使用参考中的 CDK 代码示例时,避免硬编码资源名称(例如
restApiName、eventBusName)。让 CDK 自动生成唯一名称,以实现可重用性和并行部署。详情请参阅aws-cdk-development技能。
实现全面的错误处理:
export const handler = async (event: SQSEvent) => {
const failures: SQSBatchItemFailure[] = [];
for (const record of event.Records) {
try {
await processRecord(record);
} catch (error) {
console.error('处理记录失败:', record.messageId, error);
failures.push({ itemIdentifier: record.messageId });
}
}
// 返回部分批次失败以供重试
return { batchItemFailures: failures };
};
始终配置 DLQ 进行错误处理:
const dlq = new sqs.Queue(this, 'DLQ', {
retentionPeriod: Duration.days(14),
});
const queue = new sqs.Queue(this, 'Queue', {
deadLetterQueue: {
queue: dlq,
maxReceiveCount: 3,
},
});
// 监控 DLQ 深度
new cloudwatch.Alarm(this, 'DLQAlarm', {
metric: dlq.metricApproximateNumberOfMessagesVisible(),
threshold: 1,
evaluationPeriods: 1,
alarmDescription: 'DLQ 中的消息需要关注',
});
启用追踪和监控:
new NodejsFunction(this, 'Function', {
entry: 'src/handler.ts',
tracing: lambda.Tracing.ACTIVE, // X-Ray 追踪
environment: {
POWERTOOLS_SERVICE_NAME: 'order-service',
POWERTOOLS_METRICS_NAMESPACE: 'MyApp',
LOG_LEVEL: 'INFO',
},
});
在构建无服务器基础设施时,使用 CDK MCP 服务器(通过 aws-cdk-development 依赖项)获取构造建议和 CDK 特定指导。
在实施之前,使用 AWS 文档 MCP 验证服务功能、区域可用性和 API 规范。
此技能包含基于 AWS 最佳实践的全面参考文档:
无服务器模式:references/serverless-patterns.md
事件驱动架构模式:references/eda-patterns.md
安全最佳实践:references/security-best-practices.md
可观测性最佳实践:references/observability-best-practices.md
性能优化:references/performance-optimization.md
部署最佳实践:references/deployment-best-practices.md
外部资源:
有关详细的实现模式、反模式和代码示例,请参阅技能目录中的综合参考资料。
每周安装
146
仓库
GitHub 星标
218
首次出现
2026年1月21日
安全审计
已安装于
claude-code120
opencode112
codex110
gemini-cli109
github-copilot103
cursor101
Contains Hooks
This skill uses Claude hooks which can execute code automatically in response to events. Review carefully before installing.
This skill provides comprehensive guidance for building serverless applications and event-driven architectures on AWS based on Well-Architected Framework principles.
Always verify AWS facts using MCP tools (mcp__aws-mcp__* or mcp__*awsdocs*__*) before answering. The aws-mcp-setup dependency is auto-loaded — if MCP tools are unavailable, guide the user through that skill's setup flow.
This skill leverages the CDK MCP server (provided via aws-cdk-development dependency) and AWS Documentation MCP for serverless guidance.
Note : The following AWS MCP servers are available separately via the Full AWS MCP Server (see
aws-mcp-setupskill) and are not bundled with this plugin:
- AWS Serverless MCP — SAM CLI lifecycle (init, deploy, local test)
- AWS Lambda Tool MCP — Direct Lambda invocation
- AWS Step Functions MCP — Workflow orchestration
- Amazon SNS/SQS MCP — Messaging and queue management
Use this skill when:
Functions should be concise and single-purpose
// ✅ GOOD - Single purpose, focused function
export const processOrder = async (event: OrderEvent) => {
// Only handles order processing
const order = await validateOrder(event);
await saveOrder(order);
await publishOrderCreatedEvent(order);
return { statusCode: 200, body: JSON.stringify({ orderId: order.id }) };
};
// ❌ BAD - Function does too much
export const handleEverything = async (event: any) => {
// Handles orders, inventory, payments, shipping...
// Too many responsibilities
};
Keep functions environmentally efficient and cost-aware :
Design for concurrency, not volume
Lambda scales horizontally - design considerations should focus on:
Concurrent execution limits
Downstream service throttling
Shared resource contention
Connection pool sizing
// Consider concurrent Lambda executions accessing DynamoDB const table = new dynamodb.Table(this, 'Table', { billingMode: dynamodb.BillingMode.PAY_PER_REQUEST, // Auto-scales with load });
// Or with provisioned capacity + auto-scaling const table = new dynamodb.Table(this, 'Table', { billingMode: dynamodb.BillingMode.PROVISIONED, readCapacity: 5, writeCapacity: 5, });
// Enable auto-scaling for concurrent load table.autoScaleReadCapacity({ minCapacity: 5, maxCapacity: 100 }); table.autoScaleWriteCapacity({ minCapacity: 5, maxCapacity: 100 });
Function runtime environments are short-lived
// ❌ BAD - Relying on local file system
export const handler = async (event: any) => {
fs.writeFileSync('/tmp/data.json', JSON.stringify(data)); // Lost after execution
};
// ✅ GOOD - Use persistent storage
export const handler = async (event: any) => {
await s3.putObject({
Bucket: process.env.BUCKET_NAME,
Key: 'data.json',
Body: JSON.stringify(data),
});
};
State management :
Applications must be hardware-agnostic
Infrastructure can change without notice:
Design for portability :
Use Step Functions for orchestration
// ❌ BAD - Lambda function chaining
export const handler1 = async (event: any) => {
const result = await processStep1(event);
await lambda.invoke({
FunctionName: 'handler2',
Payload: JSON.stringify(result),
});
};
// ✅ GOOD - Step Functions orchestration
const stateMachine = new stepfunctions.StateMachine(this, 'OrderWorkflow', {
definition: stepfunctions.Chain
.start(validateOrder)
.next(processPayment)
.next(shipOrder)
.next(sendConfirmation),
});
Benefits of Step Functions :
Event-driven over synchronous request/response
// Pattern: Event-driven processing
const bucket = new s3.Bucket(this, 'DataBucket');
bucket.addEventNotification(
s3.EventType.OBJECT_CREATED,
new s3n.LambdaDestination(processFunction),
{ prefix: 'uploads/' }
);
// Pattern: EventBridge integration
const rule = new events.Rule(this, 'OrderRule', {
eventPattern: {
source: ['orders'],
detailType: ['OrderPlaced'],
},
});
rule.addTarget(new targets.LambdaFunction(processOrderFunction));
Benefits :
Operations must be idempotent
// ✅ GOOD - Idempotent operation
export const handler = async (event: SQSEvent) => {
for (const record of event.Records) {
const orderId = JSON.parse(record.body).orderId;
// Check if already processed (idempotency)
const existing = await dynamodb.getItem({
TableName: process.env.TABLE_NAME,
Key: { orderId },
});
if (existing.Item) {
console.log('Order already processed:', orderId);
continue; // Skip duplicate
}
// Process order
await processOrder(orderId);
// Mark as processed
await dynamodb.putItem({
TableName: process.env.TABLE_NAME,
Item: { orderId, processedAt: Date.now() },
});
}
};
Implement retry logic with exponential backoff :
async function withRetry<T>(fn: () => Promise<T>, maxRetries = 3): Promise<T> {
for (let i = 0; i < maxRetries; i++) {
try {
return await fn();
} catch (error) {
if (i === maxRetries - 1) throw error;
await new Promise(resolve => setTimeout(resolve, Math.pow(2, i) * 1000));
}
}
throw new Error('Max retries exceeded');
}
For detailed implementation patterns with full code examples, see the reference documentation:
File : references/eda-patterns.md
File : references/serverless-patterns.md
Important : When using CDK code examples from references, avoid hardcoding resource names (e.g.,
restApiName,eventBusName). Let CDK generate unique names automatically to enable reusability and parallel deployments. Seeaws-cdk-developmentskill for details.
Implement comprehensive error handling :
export const handler = async (event: SQSEvent) => {
const failures: SQSBatchItemFailure[] = [];
for (const record of event.Records) {
try {
await processRecord(record);
} catch (error) {
console.error('Failed to process record:', record.messageId, error);
failures.push({ itemIdentifier: record.messageId });
}
}
// Return partial batch failures for retry
return { batchItemFailures: failures };
};
Always configure DLQs for error handling :
const dlq = new sqs.Queue(this, 'DLQ', {
retentionPeriod: Duration.days(14),
});
const queue = new sqs.Queue(this, 'Queue', {
deadLetterQueue: {
queue: dlq,
maxReceiveCount: 3,
},
});
// Monitor DLQ depth
new cloudwatch.Alarm(this, 'DLQAlarm', {
metric: dlq.metricApproximateNumberOfMessagesVisible(),
threshold: 1,
evaluationPeriods: 1,
alarmDescription: 'Messages in DLQ require attention',
});
Enable tracing and monitoring :
new NodejsFunction(this, 'Function', {
entry: 'src/handler.ts',
tracing: lambda.Tracing.ACTIVE, // X-Ray tracing
environment: {
POWERTOOLS_SERVICE_NAME: 'order-service',
POWERTOOLS_METRICS_NAMESPACE: 'MyApp',
LOG_LEVEL: 'INFO',
},
});
Use the CDK MCP server (via aws-cdk-development dependency) for construct recommendations and CDK-specific guidance when building serverless infrastructure.
Use AWS Documentation MCP to verify service features, regional availability, and API specifications before implementing.
This skill includes comprehensive reference documentation based on AWS best practices:
Serverless Patterns : references/serverless-patterns.md
Event-Driven Architecture Patterns : references/eda-patterns.md
Security Best Practices : references/security-best-practices.md
Observability Best Practices : references/observability-best-practices.md
External Resources :
For detailed implementation patterns, anti-patterns, and code examples, refer to the comprehensive references in the skill directory.
Weekly Installs
146
Repository
GitHub Stars
218
First Seen
Jan 21, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
claude-code120
opencode112
codex110
gemini-cli109
github-copilot103
cursor101
scaffold-exercises脚手架工具:自动化创建符合规范的练习目录结构
1,100 周安装
Doublecheck AI 内容验证工具 - GitHub Copilot 三层事实核查流程,自动识别幻觉风险
1,100 周安装
Everything Claude 代码规范:JavaScript 项目开发规范与提交指南
1,100 周安装
Web开发最佳实践指南:Lighthouse安全、兼容性与代码质量优化
72 周安装
UI/UX Pro Max - 智能设计助手:配色、字体、图表与最佳实践数据库
1,100 周安装
艺术家工作区搭建指南 - 快速创建智能体工作环境与目录结构
1,100 周安装
Performance Optimization : references/performance-optimization.md
Deployment Best Practices : references/deployment-best-practices.md