Skip to content
Back to skills

Aws Lambda

ASecurity

> **Verification Tier:** `code_example_tested` | **Last Verified:** 2026-11-18 > **Official Docs:** https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html

  • 13 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 2, 2026
ai-agentsbashawsapidatabasesecurity

Works with

  • cli
  • api

Security analysis

A96/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro scans all 2 files and shows the line behind each finding

Scanned December 2, 2026

npx -y skills add ashish7802/awesome-api-skills --skill aws-lambda --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Aws Lambda?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Aws Lambda
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ashish7802-aws-lambda/badge)](https://www.skillsdirectory.com/skills/ashish7802-aws-lambda)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
# 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

Files in this skill

  • SKILL.md3 KB
  • examples/quickstart.ts725 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.