<< All versions

Skill v1.0.0

currentAutomated scan100/100
kienbui1995/magic-powers/lambda-serverless
──Details
PublishedNovember 21, 2026 at 12:29 PM
Content Hashsha256:e33377b1ec418f8c...
Git SHA1451c9aaf4f2
──Files
Files (1 file, 9.0 KB)
SKILL.md9.0 KBactive
SKILL.md · 157 lines · 9.0 KB

name: lambda-serverless description: Use when building Lambda functions, designing serverless architectures, configuring event sources, managing concurrency and cold starts, or setting up Lambda@Edge. Covers AWS DVA-C02 and SAP-C02 serverless domains. metadata: version: "1.0.0"


AWS Lambda Serverless

When to Use

  • Building event-driven functions with AWS Lambda
  • Designing serverless architectures on AWS
  • Configuring event source mappings (SQS, DynamoDB Streams, Kinesis)
  • Managing Lambda concurrency, cold starts, and provisioned concurrency
  • Deploying Lambda@Edge or CloudFront Functions for edge computing
  • Preparing for AWS DVA-C02 or SAP-C02 exams

Core Jobs

1. Lambda Triggers (Event Sources)

SourceInvocationConcurrencyOrdering
API Gateway / ALBSynchronous (push)Per-requestN/A
S3Asynchronous (push)Per-eventNot guaranteed
SNSAsynchronous (push)Per-messageNot guaranteed
EventBridgeAsynchronous (push)Per-eventNot guaranteed
SQSPolling (event source mapping)Batch-basedFIFO within queue
DynamoDB StreamsPolling (event source mapping)Per-shardOrdered per shard
Kinesis Data StreamsPolling (event source mapping)Per-shardOrdered per shard
CognitoSynchronous (trigger type specific)Per-eventN/A
Step FunctionsSynchronous or asyncPer-executionN/A

Push model (API GW, S3, SNS): AWS service invokes Lambda directly. Pull model / Event source mapping (SQS, Kinesis, DynamoDB Streams): Lambda polls the source.

2. Concurrency Management

TypeDescriptionUse Case
Unreserved concurrencyShared pool across all functionsDefault; functions share account limit
Reserved concurrencyGuaranteed + maximum capEnsure function always has capacity; prevent throttling other functions
Provisioned concurrencyPre-initialized execution environmentsEliminate cold starts for latency-sensitive functions

Account limit: 1,000 concurrent executions per region by default (can request increase). Reserved concurrency = 0: effectively disables the function (throttles all invocations).

Concurrency calculation: concurrency = (requests/second) × (average function duration in seconds) Example: 500 req/s × 0.2s average = 100 concurrent executions needed.

3. Cold Starts

Cold start occurs when:

  • No warm execution environment available
  • Function not invoked for several minutes (environment recycled)
  • Burst traffic exceeds warm environments

Cold start duration by runtime (approximate):

  • Java, .NET, Kotlin: 500ms–2s (JVM initialization)
  • Python, Node.js, Go, Ruby: 50–200ms (lighter runtimes)
  • Custom container: varies (container pull adds overhead)

Cold start mitigations:

  1. Provisioned concurrency — pre-initialize environments; eliminates cold starts (costs money continuously)
  2. Smaller deployment package — less code to load; faster init
  3. Minimize imports/initialization code — move work outside handler to module-level (runs once)
  4. SnapStart (Java) — snapshot initialized environment; restore on cold start (sub-100ms for Java)
  5. Keep warm (not recommended) — scheduled pings every 5 minutes; not reliable and wasteful

4. Event Source Mapping Configuration

SQS + Lambda:

  • Batch size: 1–10,000 messages
  • Batch window: 0–300 seconds (wait to fill batch before invocation)
  • Visibility timeout: must be > Lambda function timeout × 6 (to prevent duplicate processing during retries)
  • On failure: DLQ on SQS queue or Lambda destination (failure destination)
  • ReportBatchItemFailures: Lambda reports specific failed messages → only failed items retried (not whole batch)

Kinesis / DynamoDB Streams + Lambda:

  • Shard iterator = one Lambda invocation per active shard
  • BisectBatchOnFunctionError: split batch and retry halves to isolate bad records
  • DestinationConfig.OnFailure: send failed records to SQS or SNS
  • MaximumRetryAttempts and MaximumRecordAgeInSeconds: limit retries to prevent infinite loops
  • ParallelizationFactor: 1–10 concurrent invocations per shard (increase throughput)

5. Lambda Layers

  • Package shared libraries and dependencies separately from function code
  • Up to 5 layers per function
  • Max unzipped size: 250MB (function + all layers combined)
  • Layers can be shared across accounts (layer-based sharing for internal libraries)
  • Common uses: AWS SDK extensions, pandas/numpy (large ML libraries), custom runtimes
  • Not for secrets: use Secrets Manager or Parameter Store; not environment variables or layers

6. Lambda@Edge and CloudFront Functions

FeatureLambda@EdgeCloudFront Functions
RuntimeNode.js, PythonJavaScript (ES5)
Max execution time5s (viewer), 30s (origin)1ms
Max memory128MB–10GB2MB
Location400+ edge locations400+ edge locations
Trigger pointsViewer request/response, Origin request/responseViewer request/response only
CostPer request + durationPer request only (cheaper)
StateStatelessStateless
Deployment regionMust deploy in us-east-1Global via CloudFront

CloudFront Functions = simple transformations (URL rewrite, header manipulation, redirect). Lambda@Edge = complex logic (auth, A/B testing, geo-routing, dynamic origin selection).

7. Lambda Destinations

  • Alternative to try/catch inside Lambda for async invocations
  • Configure on-success and on-failure destinations:
  • SQS queue, SNS topic, EventBridge bus, another Lambda function
  • Provides full invocation record (input + output/error) to destination
  • More flexible than DLQ (which only sends failed event payload)

Key Concepts

  • Execution environment — isolated container with function code, runtime, layers, and env vars; reused for warm invocations
  • Handler — entry point function Lambda invokes (module.handler for Node.js, module.handler for Python)
  • Execution role — IAM role Lambda assumes; defines what AWS services the function can call
  • Resource-based policy — policy on the Lambda function itself; controls who can invoke it (other accounts, services)
  • Lambda function URL — built-in HTTPS endpoint for Lambda without API Gateway; supports IAM or no auth
  • Lambda extensions — lightweight processes running alongside Lambda function (observability agents, secrets caching)
  • SnapStart — Java 11+ feature: snapshot initialized state of execution environment for sub-100ms cold starts
  • Ephemeral storage /tmp — 512MB to 10GB per execution environment; NOT shared between invocations

Checklist

  • [ ] SQS visibility timeout set to > Lambda timeout × 6 (prevent duplicate processing)?
  • [ ] Reserved concurrency set to prevent one function from consuming all account concurrency?
  • [ ] Provisioned concurrency configured for latency-sensitive APIs?
  • [ ] Initialization code (clients, connections) outside handler function (module-level)?
  • [ ] ReportBatchItemFailures enabled for SQS event source (partial batch success)?
  • [ ] Lambda destinations configured for async invocations (on-success and on-failure)?
  • [ ] Layers used for shared dependencies (not duplicated across functions)?
  • [ ] Lambda execution role follows least-privilege principle?

Output Format

  • 🔴 Critical — SQS visibility timeout < Lambda timeout (guarantees duplicate processing); Lambda function consuming full account concurrency (starving other functions); no error handling on async invocations (silent failures)
  • 🟡 Warning — Cold starts affecting user-facing API (provisioned concurrency not configured); no DLQ/destination for async function failures; large deployment package (slow cold starts)
  • 🟢 Suggestion — Lambda SnapStart for Java functions; Lambda function URL instead of API Gateway for simple use cases; layers for shared dependencies

Exam Tips

  • SQS + Lambda: batch size up to 10,000; visibility timeout must be > Lambda timeout (to avoid duplicate processing during retries)
  • Provisioned concurrency = eliminates cold starts; costs money even when idle (pre-initialized environments running 24/7)
  • Lambda execution role = what Lambda CAN do (outbound AWS API calls); resource policy = who CAN invoke Lambda (inbound)
  • Max execution timeout = 15 minutes; for longer tasks use Step Functions + Fargate or ECS tasks
  • Lambda@Edge = deployed in us-east-1 ONLY but runs globally at CloudFront edge; CloudFront Functions = cheaper, sub-millisecond, simpler
  • Layers = shared dependencies (SDK, pandas); NOT for secrets — use Secrets Manager or Parameter Store instead
  • BisectBatchOnFunctionError (Kinesis/DynamoDB Streams): splits failing batch in half to isolate bad records, reducing reprocessing
  • ReportBatchItemFailures (SQS): return failed message IDs — only those specific messages are retried, not the whole batch
All versions