| name | aws-serverless |
| type | reference |
| description | Provides AWS serverless architecture patterns for Lambda, API Gateway, DynamoDB, SQS, and SAM/CDK. Use when working with AWS serverless files (serverless.yml, CDK stacks) or when the user mentions Lambda, API Gateway, serverless, or AWS SAM. |
| paths | ["**/serverless.yml","**/template.yaml","**/cdk/**","**/sam/**"] |
| effort | 3 |
| allowed-tools | Read, Glob, Grep |
| user-invocable | true |
| when_to_use | When building or deploying serverless applications on AWS with Lambda, API Gateway, DynamoDB, or SAM/CDK |
AWS Serverless
Critical rules (non-obvious)
- Initialize clients OUTSIDE handler — Lambda reuses execution environments across invocations; creating clients inside costs 100-500ms per cold start
context.callbackWaitsForEmptyEventLoop = false — prevents Node.js from hanging on open async handles (DB connections, etc.)
- SQS
VisibilityTimeout = 6× Lambda timeout — if Lambda takes 30s, set 180s; otherwise messages return to queue mid-processing
FunctionResponseTypes: [ReportBatchItemFailures] — partial batch failure; without this, any single failure retries the entire batch
- Never use
* in Access-Control-Allow-Origin with credentials: true — browsers block it; use explicit origin
Lambda handler pattern
const { DynamoDBClient } = require("@aws-sdk/client-dynamodb");
const { DynamoDBDocumentClient, GetCommand } = require("@aws-sdk/lib-dynamodb");
const docClient = DynamoDBDocumentClient.from(new DynamoDBClient({}));
exports.handler = async (event, context) => {
context.callbackWaitsForEmptyEventLoop = false;
try {
const body = typeof event.body === "string" ? JSON.parse(event.body) : event.;
result = docClient.( ({
: process..,
: { : body. },
}));
{ : , : { : }, : .(result.) };
} (err) {
.(.({ : err., : context. }));
{ : err. ?? , : .({ : err. }) };
}
};