Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Is that skill safe to install?
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
Are you the author of Aws Lambda?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/ashish7802-aws-lambda)
# AWS Lambda Handler Patterns Skill
> **Verification Tier:** `code_example_tested` | **Last Verified:** 2026-11-18
> **Official Docs:** https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html
## Overview
AWS Lambda runs event-driven serverless functions triggered by API Gateway, SQS, EventBridge, DynamoDB Streams, and S3. Production reliability depends on idempotent handlers, partial batch failure reporting, execution-context reuse, and strict timeout budgets.
## Installation
```bash
npm install -D @types/aws-lambda
```
## Authentication
Rely exclusively on the Lambda Function **IAM Execution Role** (temporary STS credentials injected into the runtime environment). Never store static AWS access keys in Lambda environment variables.
## Core Concepts
- **Execution Environment Reuse**: Initialize SDK clients and database pools outside the exported `handler` so warm invocations reuse TCP/TLS connections.
- **SQS Partial Batch Failures**: Enable `FunctionResponseTypes: ["ReportBatchItemFailures"]` on the SQS Event Source Mapping and return `{ batchItemFailures: [{ itemIdentifier: record.messageId }] }`. Without this, throwing an error re-queues the ENTIRE batch and re-processes already-succeeded messages!
- **Timeout Guarding**: Set outbound HTTP/DB timeouts below `context.getRemainingTimeInMillis() - 1000` so you can log clean diagnostics before Lambda hard-kills the process.
## Error Handling & Rate Limits
- Configure an SQS Dead-Letter Queue (DLQ) with `maxReceiveCount` (e.g., 3–5) to isolate poison-pill messages.
- Set `VisibilityTimeout` on the source SQS queue to at least **6x the Lambda function timeout**.
- Configure Reserved Concurrency on downstream-sensitive functions to avoid exhausting relational DB connection pools.
## Security Best Practices
- Apply least-privilege IAM policies scoped to exact queue/table/bucket ARNs.
- Validate all API Gateway / EventBridge event payloads at runtime (e.g., with `zod`).
- Never log raw `Authorization` headers or secret values to CloudWatch Logs.
## AI Pitfalls
- Throwing on a single bad SQS message without `ReportBatchItemFailures`, causing infinite reprocessing of healthy records in the same batch.
- Opening a fresh database/SDK connection inside `handler()` on every invocation.
- Setting SQS `VisibilityTimeout` shorter than Lambda timeout, causing duplicate concurrent execution.
## Production Checklist
- [ ] SDK/DB clients initialized at module scope outside `handler`
- [ ] SQS handlers return `SQSBatchResponse` with `batchItemFailures`
- [ ] SQS `VisibilityTimeout >= 6 * LambdaTimeout` and DLQ configured
- [ ] Outbound requests use timeouts bounded by remaining Lambda execution time
## References
- [Lambda with Amazon SQS](https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html)
- [Lambda Best Practices](https://docs.aws.amazon.com/lambda/latest/dg/best-practices.html)
## Related skills
- [`aws-bedrock`](../aws-bedrock/SKILL.md) — works well with
- [`aws-s3`](../aws-s3/SKILL.md) — works well with
- [`aws-dynamodb`](../aws-dynamodb/SKILL.md) — works well with