Skip to content

AWS Lambda Interview Questions

These AWS Lambda interview questions focus on Node.js handlers, cold starts, IAM, API Gateway integration, and Lambda layers.

AWS Lambda Interview Overview

AWS Lambda runs your code on demand without managing servers: you upload a handler, configure memory and timeout, and AWS scales instances per invoke. Billing is per millisecond of execution and request count, so efficient handlers and right-sized memory directly affect cost.

Node.js Lambdas are common for HTTP APIs behind API Gateway, event processing (S3, SQS, DynamoDB streams), and scheduled jobs. Interviews probe cold starts, the event/context contract, least-privilege IAM, and how to structure code for reuse via layers and environment configuration.

AWS Lambda Interview Cheatsheet

Quick answers you can expand in a real interview.

Topic Short answer
Handler signature export async function handler(event, context) { ... }
Cold start First invoke or new execution environment loads runtime + init code.
Memory More memory also grants proportional CPU; tune with power tuning.
IAM role Execution role grants AWS API access; follow least privilege.
API Gateway Proxy integration passes full request as event; return statusCode + body.
Layer Shared dependencies or binaries mounted under /opt/nodejs.

15 AWS Lambda Interview Questions with Answers

Use the short version first, then offer trade-offs if the interviewer wants depth.

1. What is AWS Lambda and when is it a good fit?

Lambda executes functions in response to events with automatic scaling from zero to high concurrency. It fits sporadic or unpredictable workloads, event-driven pipelines, and thin API backends where you want no server patching. It is a poor fit for long-running processes, sustained high CPU without burst patterns, or workloads needing persistent local state on one machine.

2. Explain cold starts and warm starts in Lambda.

A cold start occurs when AWS provisions a new execution environment: downloading your package, starting the Node runtime, and running top-level initialization code. Subsequent invokes on the same environment are warm and skip most of that work. Mitigate cold starts with provisioned concurrency, smaller bundles, and lazy imports of heavy modules.

3. What do the event and context objects contain in a Node.js handler?

The event shape depends on the trigger—API Gateway proxy events include httpMethod, path, headers, and body; SQS events wrap Records arrays. context provides awsRequestId, getRemainingTimeInMillis(), functionName, and memoryLimitInMB. Use context to detect timeouts and log correlation ids.

4. How do you return a proper HTTP response from Lambda behind API Gateway (REST)?

Return an object with statusCode, headers (e.g., Content-Type), and body as a string—often JSON.stringify(data). Enable CORS headers explicitly if browsers call the API directly. For Lambda proxy integration, API Gateway maps this object directly to the HTTP response without Velocity templates.

5. How does IAM fit into Lambda security?

Each function has an execution role whose policies allow actions like dynamodb:GetItem or s3:PutObject. Grant only what the handler needs—never attach AdministratorAccess. Resource ARNs should be scoped to specific tables or buckets. Cross-account access uses role assumption with trust policies.

6. What are Lambda environment variables and best practices?

Environment variables configure handlers without code changes—database URLs, feature flags, stage names. Mark secrets with encryption using KMS-backed Lambda env encryption or fetch from Secrets Manager at init (cached outside handler). Do not commit secrets into deployment packages.

7. What is a Lambda layer and when would you use one?

Layers are zip archives merged into /opt in the execution environment—commonly for node_modules shared across functions or native binaries like sharp. They reduce deployment package size per function and speed updates when only app code changes. Keep layer versions immutable and document compatibility with runtime versions.

8. How do memory and timeout settings affect performance and cost?

Memory from 128 MB to 10 GB also scales CPU proportionally; more memory can finish CPU-bound work faster and sometimes cost less overall. Timeout caps maximum run time (up to 15 minutes). Set timeout below client limits and use getRemainingTimeInMillis to flush work gracefully before hard kill.

9. Compare API Gateway REST vs HTTP API vs Function URL for exposing Lambda.

REST API offers full feature set (API keys, request validation, WAF integration). HTTP API is cheaper and lower latency for common proxy use cases. Function URL adds a dedicated HTTPS endpoint on the function with built-in auth modes. Choose based on auth needs, cost, and whether you need API management features.

10. How should you structure Node.js code for Lambda reusability?

Keep the handler thin: parse event, call shared service modules, map errors to status codes. Initialize SDK clients and database connections outside the handler so warm invokes reuse them. Use dependency injection for testability. Avoid global mutable state unless you understand concurrency on one container.

11. What triggers can invoke Lambda besides API Gateway?

S3 object events, SQS queues, DynamoDB streams, EventBridge schedules and rules, SNS notifications, Kinesis records, and direct SDK invoke. Each event source has batching, retry, and DLQ options—e.g., SQS triggers respect visibility timeout and can route failures to a DLQ after max receives.

12. What is provisioned concurrency?

Provisioned concurrency keeps a configured number of execution environments initialized, eliminating cold starts for that capacity. It adds cost even when idle. Use for latency-sensitive endpoints with predictable traffic; combine with auto-scaling policies on provisioned units for diurnal patterns.

13. How do you handle errors and retries in Lambda?

Uncaught exceptions fail the invoke; synchronous callers see the error, async event sources retry per their policy. Return partial batch failures for SQS FIFO/Lambda pollers when supported. Log structured errors with awsRequestId, use DLQs for async pipelines, and distinguish client errors (4xx) from server errors (5xx) in HTTP handlers.

14. What runtime considerations apply to Node.js 20+ on Lambda?

Use the provided Amazon Linux 2023 runtime, ES modules if configured in package.json type module, and keep native addons compiled for the Lambda architecture (x86_64 vs arm64 Graviton). arm64 often improves price/performance. Match local Node version to runtime for consistent behavior.

15. How would you test a Lambda handler locally?

Unit-test pure functions with sample events from AWS documentation or sam local/API Gateway emulator. Mock AWS SDK clients with aws-sdk-client-mock. Integration tests deploy to a dev stage or use LocalStack with caveats. Snapshot representative API Gateway and SQS events to catch schema drift.

Common Mistakes

  • Creating huge deployment bundles that worsen cold starts.
  • Opening security groups or IAM policies far beyond what the handler needs.
  • Reconnecting to the database on every invoke instead of reusing warm connections.
  • Returning plain objects without statusCode/body string for API Gateway proxy integration.

Key Takeaways

  • Lambda is event-driven and stateless—optimize init code and connection reuse.
  • Cold starts are managed with bundle size, arm64, and provisioned concurrency.
  • IAM execution roles must follow least privilege per trigger and resource.
  • API Gateway proxy responses require explicit HTTP-shaped return objects.

Pro Tip

Mention power tuning: increasing memory can reduce duration enough to lower total cost—shows you understand Lambda economics, not just syntax.