serverless-patterns-advanced
Advanced Serverless patterns — Lambda idempotency (Lambda Powertools + DynamoDB persistence layer), Lambda cost model (pricing formula, break-even vs containers), and CloudWatch Insights observability queries for cold starts, duration, and errors.
Best use case
serverless-patterns-advanced is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Advanced Serverless patterns — Lambda idempotency (Lambda Powertools + DynamoDB persistence layer), Lambda cost model (pricing formula, break-even vs containers), and CloudWatch Insights observability queries for cold starts, duration, and errors.
Teams using serverless-patterns-advanced should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/serverless-patterns-advanced/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How serverless-patterns-advanced Compares
| Feature / Agent | serverless-patterns-advanced | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Advanced Serverless patterns — Lambda idempotency (Lambda Powertools + DynamoDB persistence layer), Lambda cost model (pricing formula, break-even vs containers), and CloudWatch Insights observability queries for cold starts, duration, and errors.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Serverless Patterns — Advanced
This skill extends `serverless-patterns` with idempotency, cost modeling, and observability. Load `serverless-patterns` first.
## When to Activate
- Lambda receives duplicate events and needs idempotency (at-least-once delivery)
- Calculating whether Lambda or containers are more cost-effective at current request volume
- Writing CloudWatch Insights queries for cold start analysis, duration percentiles, or error rates
---
## Idempotency
Lambda can be invoked multiple times for the same event (at-least-once delivery). Always design for idempotency.
```typescript
import { makeHandlerIdempotent } from '@aws-lambda-powertools/idempotency';
import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb';
const persistenceStore = new DynamoDBPersistenceLayer({
tableName: 'IdempotencyTable',
});
// Wrap handler — duplicate events return cached result
export const handler = makeHandlerIdempotent(
async (event: OrderEvent) => {
await chargePayment(event.paymentId, event.amount);
await createOrder(event);
return { orderId: event.orderId, status: 'created' };
},
{ persistenceStore }
);
```
```yaml
# Required DynamoDB table
IdempotencyTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: id
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
TimeToLiveSpecification:
AttributeName: expiration
Enabled: true
BillingMode: PAY_PER_REQUEST
```
---
## Cost Model
**Lambda pricing (us-east-1):**
- Requests: $0.20 per 1M invocations
- Duration: $0.0000166667 per GB-second
- Provisioned Concurrency: $0.0000041667 per GB-second (always-on)
**Break-Even: Lambda vs. Container**
```
Lambda cost/month = requests × $0.0000002 + (avg_duration_s × memory_GB × requests × $0.0000166667)
Example: 10M requests/month, 200ms avg, 512MB
= 10M × $0.0000002 + (0.2 × 0.5 × 10M × $0.0000166667)
= $2 + $16.67
= ~$18.67/month
ECS Fargate (0.25 vCPU, 0.5GB) = ~$12/month (continuous)
Rule of thumb: Lambda wins below ~5M requests/month or spiky traffic.
Containers win with constant high-volume predictable load.
```
---
## Observability
```bash
# CloudWatch Insights — Lambda performance
fields @timestamp, @duration, @billedDuration, @memorySize, @maxMemoryUsed, @initDuration
| filter @type = "REPORT"
| stats avg(@duration), max(@duration), avg(@initDuration) by bin(5m)
# Cold starts only
fields @timestamp, @initDuration
| filter @type = "REPORT" and ispresent(@initDuration)
| stats count(), avg(@initDuration) by bin(1h)
# Errors
fields @timestamp, @message
| filter @message like /ERROR/
| sort @timestamp desc
| limit 50
```
## Reference
- `serverless-patterns` — cold starts, Step Functions, Lambda Powertools (Logger, Metrics, Tracer)
- `edge-patterns` — Cloudflare Workers, Vercel Edge Middleware
- `observability` — OpenTelemetry, Grafana, distributed tracing
- `chaos-engineering` — Testing Lambda failure modes (throttling, DLQ exhaustion)Related Skills
zero-trust-patterns
Zero-Trust security patterns — mTLS between microservices (Istio/SPIFFE), SPIRE workload identity, OPA/Envoy authorization, NetworkPolicy default-deny-all, short-lived credentials, service mesh security, and Kubernetes RBAC hardening.
webrtc-patterns
WebRTC patterns — peer connection setup, ICE/STUN/TURN configuration, signaling server design, SFU vs mesh topology, screen sharing, media track management, and reconnect/ICE restart handling.
webhook-patterns
Webhook patterns for receiving, verifying (HMAC), and idempotently processing third-party events. Covers Stripe, GitHub, and generic webhook patterns, delivery guarantees, retry handling, and testing.
wasm-patterns
WebAssembly patterns: wasm-pack, wasm-bindgen (JS↔Wasm interop), WASI, Component Model, wasm-opt, Rust-to-WASM compilation, JS integration (web workers, streaming instantiation), and production deployment (CDN, Content-Type headers).
ux-micro-patterns
UX micro-patterns for every product state: Empty States, Loading States (skeleton screens, spinners, optimistic UI), Error States, Success States, Confirmation Dialogs, Onboarding Flows, and Progressive Disclosure. These patterns apply to every feature — done wrong, they're the biggest source of user confusion.
typescript-patterns
TypeScript patterns — type system best practices, strict mode, utility types, generics, discriminated unions, error handling with Result types, and module organization. Core patterns for production TypeScript.
typescript-patterns-advanced
Advanced TypeScript — mapped types, template literal types, conditional types, infer, type guards, decorators, async patterns, testing with Vitest/Jest, and performance. Extends typescript-patterns.
typescript-monorepo-patterns
TypeScript monorepo patterns with Turborepo + pnpm workspaces. Covers package structure, shared configs, task pipeline caching, build orchestration, and publishing strategy.
terraform-patterns
Infrastructure as Code with Terraform — project structure, remote state, modules, workspace strategy, AWS/GCP patterns, CI/CD integration, and security hardening. The standard for managing production infrastructure.
tdd-workflow-advanced
TDD anti-patterns — writing code before tests, testing implementation details instead of behavior, using waitForTimeout as a sync strategy, chaining tests that share state, mocking the system under test instead of its dependencies.
swiftui-patterns
SwiftUI architecture patterns, state management with @Observable, view composition, navigation, performance optimization, and modern iOS/macOS UI best practices.
swift-patterns
Core Swift patterns — value vs reference types, protocols, generics, optionals, Result, error handling, Codable, and module organization. Foundation for all Swift development.