By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
(For AWS Solutions Architect – Associate & Real-World Production)
You’re a cloud engineer at a fintech startup. Your team just migrated a critical payment processing microservice to AWS Lambda. At first, everything works—until Black Friday hits. Suddenly, latency spikes from 50ms to 5s, and your CTO is getting paged at 3 AM. The culprit? Cold starts and unmanaged concurrency.
Lambda’s execution model isn’t just "serverless magic"—it’s a trade-off between cost, performance, and scalability. Ignore it, and you’ll either: - Overpay (provisioned concurrency you don’t need), or - Break under load (throttled requests, timeouts, or cold-start delays).
This guide will teach you:✅ How Lambda actually runs your code (hint: it’s not "always on").✅ How to control concurrency (reserved vs. provisioned vs. burst).✅ How to minimize cold starts (without overspending).✅ How to debug real-world issues (latency spikes, throttling, timeouts).
Real-world scenario:You inherit a Lambda function that processes user uploads to S3. During peak hours, users complain of 5–10 second delays before their files appear. Your logs show high Init Duration (cold starts). You need to fix this without rewriting the function and without blowing up costs.
Init Duration
init
429 Too Many Requests
pandas
numpy
lambda:*
cloudwatch:*
iam:PassRole
aws --version
Goal: Deploy a function and measure cold vs. warm starts.
# Create a deployment package (Python example) mkdir lambda-coldstart-demo cd lambda-coldstart-demo echo 'def lambda_handler(event, context): return { "statusCode": 200, "body": "Hello from Lambda!" }' > lambda_function.py # Zip it (required for CLI upload) zip function.zip lambda_function.py
# Create IAM role for Lambda aws iam create-role --role-name lambda-execution-role --assume-role-policy-document '{ "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Principal": {"Service": "lambda.amazonaws.com"}, "Action": "sts:AssumeRole" }] }' # Attach basic execution policy aws iam attach-role-policy --role-name lambda-execution-role --policy-arn arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole # Create Lambda function aws lambda create-function \ --function-name coldstart-demo \ --runtime python3.9 \ --role arn:aws:iam::YOUR_ACCOUNT_ID:role/lambda-execution-role \ --handler lambda_function.lambda_handler \ --zip-file fileb://function.zip
# First invocation (cold start) aws lambda invoke --function-name coldstart-demo --payload '{}' output.json cat output.json # Should return {"statusCode": 200, "body": "Hello from Lambda!"} # Check CloudWatch Logs (look for "Init Duration") aws logs get-log-events \ --log-group-name /aws/lambda/coldstart-demo \ --log-stream-name $(aws logs describe-log-streams --log-group-name /aws/lambda/coldstart-demo --query 'logStreams[0].logStreamName' --output text) \ --query 'events[?contains(message, `Init Duration`)].message' \ --output text
Expected Output:
INIT START Runtime Version: python:3.9.v14 Runtime Version ARN: arn:aws:lambda:us-east-1::runtime:...INIT DURATION 123.45 ms
? Key Takeaway: The first invocation has an Init Duration (cold start). Subsequent invocations won’t show this (warm start).
Goal: Simulate 100 concurrent requests and observe latency spikes.
aws lambda invoke
# Install parallel (for concurrent invocations) brew install parallel # macOS # sudo apt-get install parallel # Linux # Run 100 concurrent invocations (simulate traffic spike) seq 1 100 | parallel -j 100 aws lambda invoke --function-name coldstart-demo --payload '{}' /dev/null
Go to AWS Console → Lambda → coldstart-demo → Monitor → Metrics: - Duration (spikes on cold starts).- Invocations (should show 100).- ConcurrentExecutions (should spike to ~100).
Duration
Invocations
ConcurrentExecutions
? Key Takeaway: Cold starts add 100ms–2s of latency per invocation. Not acceptable for APIs!
Goal: Eliminate cold starts by pre-warming containers.
# Set 10 pre-warmed instances aws lambda put-provisioned-concurrency-config \ --function-name coldstart-demo \ --qualifier $LATEST \ --provisioned-concurrent-executions 10
# Check status (should say "READY") aws lambda get-provisioned-concurrency-config \ --function-name coldstart-demo \ --qualifier $LATEST # Test again (should be fast, no Init Duration) aws lambda invoke --function-name coldstart-demo --payload '{}' output.json
? Key Takeaway: No more Init Duration in logs. Latency drops to ~1–10ms.
Goal: Prevent a runaway function from DDoS-ing your database.
# Limit to 50 concurrent executions aws lambda put-function-concurrency \ --function-name coldstart-demo \ --reserved-concurrent-executions 50
# Try 100 concurrent invocations again seq 1 100 | parallel -j 100 aws lambda invoke --function-name coldstart-demo --payload '{}' /dev/null # Check CloudWatch for throttles aws logs get-log-events \ --log-group-name /aws/lambda/coldstart-demo \ --query 'events[?contains(message, `ThrottlingException`)].message' \ --output text
ThrottlingException: Rate Exceeded
? Key Takeaway: Reserved Concurrency prevents overload but limits scalability.
Goal: Reduce Init Duration without Provisioned Concurrency.
# Update function to Node.js (faster cold starts) echo 'exports.handler = async (event) => { return { statusCode: 200, body: "Hello from Node.js!" }; };' > index.js zip function-node.zip index.js aws lambda update-function-code \ --function-name coldstart-demo \ --zip-file fileb://function-node.zip \ --runtime nodejs18.x
# First invocation (should be faster than Python) aws lambda invoke --function-name coldstart-demo --payload '{}' output.json
? Key Takeaway: Node.js/Python cold starts are ~2x faster than Java/.NET.
# Create a layer (e.g., for pandas) mkdir -p python/lib/python3.9/site-packages pip install pandas -t python/lib/python3.9/site-packages/ zip -r layer.zip python # Publish layer aws lambda publish-layer-version \ --layer-name pandas-layer \ --zip-file fileb://layer.zip \ --compatible-runtimes python3.9 # Attach layer to function aws lambda update-function-configuration \ --function-name coldstart-demo \ --layers arn:aws:lambda:us-east-1:YOUR_ACCOUNT_ID:layer:pandas-layer:1
? Key Takeaway: Layers reduce deployment package size → faster cold starts.
*
AWSLambdaBasicExecutionRole
Environment=prod
Owner=team-x
CostCenter=123
PROD
STAGING
$LATEST
Throttles
Errors
SuccessfulPayments
FailedUploads
429
❌ Reserved Concurrency (limits max instances, doesn’t reduce cold starts).
"You have a Lambda function that processes S3 uploads. During peak hours, users see 10s delays. What’s the issue?"
❌ S3 latency (unlikely, S3 is fast).
"How do you prevent a Lambda function from overwhelming a database with 100 max connections?"
❌ Use Provisioned Concurrency (doesn’t limit max instances).
"Which runtime has the fastest cold starts?"
You have a Lambda function that processes SQS messages. During a traffic spike, 50% of messages fail with ThrottlingException. Fix it without increasing costs.
ThrottlingException
# Set Reserved Concurrency to match SQS batch size (e.g., 10) aws lambda put-function-concurrency \ --function-name sqs-processor \ --reserved-concurrent-executions 10
Why it works:- SQS triggers Lambda with a batch size (default: 10).- Reserved Concurrency = 10 ensures no throttling while not over-provisioning.
aws lambda put-provisioned-concurrency-config --provisioned-concurrent-executions 10
aws lambda put-function-concurrency --reserved-concurrent-executions 50
aws lambda publish-layer-version --layer-name my-layer
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.