AWS Lambda

AWS Lambda

Top Interview Questions

About AWS Lambda

Introduction to AWS Lambda

AWS Lambda is a serverless computing service provided by Amazon Web Services (AWS) that allows developers to run code without provisioning or managing servers. Introduced in 2014, AWS Lambda enables users to execute code in response to events, such as changes in data, HTTP requests, or system triggers. With Lambda, developers can focus entirely on writing application logic while AWS automatically handles infrastructure management, scaling, and availability.

AWS Lambda is a key part of the serverless computing model and is widely used to build scalable, cost-effective, and event-driven applications.

What Is Serverless Computing?

Despite its name, serverless computing does not mean that servers do not exist. Instead, it means that developers do not need to manage servers themselves. In traditional computing models, developers must set up servers, install software, manage scaling, and handle maintenance. Serverless computing abstracts all of this complexity.

With AWS Lambda, AWS takes responsibility for:

  • Server provisioning

  • Operating system maintenance

  • Scaling and load balancing

  • Fault tolerance and availability

This allows developers to spend more time on innovation and less time on infrastructure management.

How AWS Lambda Works

AWS Lambda runs code in response to events. An event can come from various AWS services or external sources. When an event occurs, Lambda automatically executes the associated function. Once the execution is complete, the resources are released.

Each Lambda function:

  • Is written in a supported programming language

  • Performs a specific task

  • Runs in an isolated environment

  • Scales automatically based on demand

Lambda functions are stateless, meaning they do not retain data between executions. If persistent storage is required, other AWS services such as Amazon S3 or DynamoDB are used.

Supported Programming Languages

AWS Lambda supports several popular programming languages, including:

  • JavaScript (Node.js)

  • Python

  • Java

  • C#

  • Go

  • Ruby

Developers can also use custom runtimes to run other languages. This flexibility allows teams to choose the language they are most comfortable with.

Key Features of AWS Lambda

1. Automatic Scaling

One of the most powerful features of AWS Lambda is automatic scaling. When multiple events occur simultaneously, Lambda automatically creates multiple instances of the function to handle the load. When demand decreases, it scales down automatically. There is no need for manual configuration.

2. Pay-as-You-Go Pricing

AWS Lambda follows a pay-as-you-go pricing model. Users are charged only for:

  • The number of requests

  • The execution time of the function

There are no charges when code is not running. This makes Lambda highly cost-effective, especially for applications with unpredictable or low traffic.

3. Event-Driven Architecture

Lambda is designed for event-driven applications. It integrates seamlessly with many AWS services such as:

  • Amazon S3 (file uploads)

  • Amazon DynamoDB (database changes)

  • Amazon API Gateway (HTTP requests)

  • Amazon CloudWatch (logs and monitoring)

This makes it easy to build applications that react to real-time events.

4. High Availability and Fault Tolerance

AWS Lambda automatically runs code across multiple availability zones within a region. This ensures high availability and fault tolerance without any additional configuration from the developer.

Common Use Cases of AWS Lambda

AWS Lambda is suitable for a wide range of use cases, including:

1. Web and API Backends

Lambda is commonly used with Amazon API Gateway to build RESTful APIs. Each API endpoint triggers a Lambda function, making it easy to create scalable backend services without managing servers.

2. Data Processing

Lambda is widely used for real-time data processing. For example:

  • Processing files uploaded to Amazon S3

  • Transforming data streams

  • Validating or filtering data

3. Automation and Scheduling

Lambda can automate tasks such as backups, resource cleanup, or system monitoring. When combined with Amazon EventBridge or CloudWatch, Lambda functions can run on schedules or system events.

4. IoT and Real-Time Applications

AWS Lambda works well with Internet of Things (IoT) applications by processing sensor data in real time and triggering actions based on events.

AWS Lambda Security

Security is an important aspect of AWS Lambda. AWS uses IAM (Identity and Access Management) to control permissions. Each Lambda function is assigned an IAM role that defines what AWS resources it can access.

Other security features include:

  • Encrypted environment variables

  • Network isolation using VPCs

  • Automatic patching and updates by AWS

These features help ensure that applications remain secure with minimal effort from developers.

Limitations of AWS Lambda

Although AWS Lambda is powerful, it has some limitations:

  • Execution time is limited (functions cannot run indefinitely)

  • Stateless nature requires external storage

  • Cold start delays may occur for infrequently used functions

  • Debugging can be more challenging than traditional servers

Despite these limitations, many of them can be managed with proper design and architecture.

Benefits of Using AWS Lambda

Some key benefits of AWS Lambda include:

  • No server management

  • Reduced operational complexity

  • High scalability

  • Cost efficiency

  • Faster development cycles

  • Easy integration with AWS services

These benefits make AWS Lambda especially attractive for startups and small teams.

AWS Lambda in Modern Cloud Architecture

AWS Lambda plays a crucial role in modern cloud-native architectures. It is often used alongside microservices, containers, and managed databases. Many organizations adopt Lambda as part of a hybrid approach, combining serverless functions with traditional services.

Lambda also supports continuous integration and deployment (CI/CD), allowing developers to quickly update and deploy new features.

Conclusion

AWS Lambda is a powerful serverless computing service that simplifies application development by removing the need for server management. Its event-driven model, automatic scaling, and cost-effective pricing make it ideal for a wide range of applications, from simple automation tasks to complex cloud-based systems.

By allowing developers to focus on writing code rather than managing infrastructure, AWS Lambda increases productivity and accelerates innovation. As cloud computing continues to evolve, AWS Lambda remains a core service that helps organizations build scalable, reliable, and efficient applications in the cloud.

Fresher Interview Questions

 

1. What is AWS Lambda?

Answer:
AWS Lambda is a serverless compute service that lets you run code without provisioning or managing servers. You only pay for the compute time you consume. Lambda automatically scales your application by running code in response to events.


2. What are the key features of AWS Lambda?

Answer:

  • Serverless: No need to manage servers.

  • Event-driven: Can be triggered by AWS services like S3, DynamoDB, API Gateway.

  • Automatic scaling: Scales with the number of requests.

  • Pay-per-use: Charged only for the execution time and requests.

  • Supports multiple languages: Node.js, Python, Java, Go, Ruby, C#, etc.


3. What is a trigger in AWS Lambda?

Answer:
A trigger is an event source that invokes a Lambda function. Examples include:

  • Uploading a file to S3

  • Updating a DynamoDB table

  • API request through API Gateway

  • A message in SNS or SQS


4. What are the limits of AWS Lambda?

Answer:

  • Maximum execution time: 15 minutes

  • Maximum deployment package size (compressed): 50 MB

  • Maximum uncompressed size: 250 MB

  • Memory allocation: 128 MB – 10,240 MB

  • Maximum concurrent executions (default): 1,000


5. What is the difference between AWS Lambda and EC2?

Feature AWS Lambda EC2
Server Management No Yes
Billing Pay per execution Pay per hour
Scaling Automatic Manual or auto-scaling groups
Use Case Event-driven, short tasks Long-running applications

6. What is a Lambda function handler?

Answer:
The handler is the entry point of a Lambda function. It’s a method that AWS Lambda calls to start execution.
Example in Python:

def lambda_handler(event, context):
    return "Hello from Lambda!"

7. Can you explain the “cold start” in Lambda?

Answer:
A cold start happens when Lambda initializes a function for the first time or after being idle. It may cause a slight delay in execution. Subsequent invocations (warm starts) are faster because the environment is already initialized.


8. What are the different types of Lambda invocation?

Answer:

  • Synchronous: Caller waits for the function to complete (e.g., API Gateway).

  • Asynchronous: Caller doesn’t wait (e.g., S3 event).

  • Poll-based: Lambda polls a service for events (e.g., Kinesis, DynamoDB streams).


9. How can you secure Lambda functions?

Answer:

  • Use IAM roles to restrict permissions.

  • Enable VPC access for private resources.

  • Use environment variables for secrets and secure them with AWS KMS.

  • Restrict triggers to trusted sources.


10. How is AWS Lambda billed?

Answer:

  • Number of requests: First 1 million requests are free; after that, you pay per request.

  • Compute time: Charged in milliseconds based on memory allocated and execution time.


11. What are Lambda Layers?

Answer:
Lambda Layers are a way to manage and share common code or libraries across multiple Lambda functions. Instead of including the same library in every function package, you can create a Layer and attach it to any function.

Example Use Cases:

  • Shared Python libraries

  • Custom logging utilities

  • Common configuration files

Benefits:

  • Reduces deployment package size

  • Promotes code reusability

  • Easier version management


12. What is the difference between Lambda environment variables and Layers?

Feature Environment Variables Layers
Purpose Store configuration/settings Share libraries/code between functions
Size Limit 4 KB total per function 50 MB (compressed)
Example DB connection strings, API keys Common libraries like Pandas, NumPy

13. What is the maximum execution duration of a Lambda function?

Answer:

  • Lambda functions can run for a maximum of 15 minutes (900 seconds) per invocation.

  • If your task takes longer, you need to break it into smaller chunks or use services like Step Functions to orchestrate multiple Lambda executions.


14. How does AWS Lambda scale?

Answer:

  • Lambda automatically scales horizontally based on the number of events.

  • Each incoming event triggers a new Lambda instance, up to the account's concurrency limit.

  • Example: If 100 S3 files are uploaded at the same time, Lambda can create 100 instances to process them concurrently.


15. What are Lambda destinations?

Answer:
Lambda Destinations allow you to send the result of an asynchronous invocation to another service.

  • Success destination: Triggered when Lambda executes successfully

  • Failure destination: Triggered when Lambda fails

Supported destinations:

  • SNS

  • SQS

  • EventBridge

  • Another Lambda function


16. How can Lambda be triggered by HTTP requests?

Answer:

  • Use Amazon API Gateway or AWS ALB (Application Load Balancer) as the trigger.

  • API Gateway receives HTTP requests and invokes your Lambda function.

  • This setup allows you to build serverless APIs.


17. How do you debug AWS Lambda functions?

Answer:

  • Use Amazon CloudWatch Logs to view execution logs.

  • Enable AWS X-Ray for tracing requests and performance bottlenecks.

  • Test Lambda locally using tools like AWS SAM CLI or Serverless Framework.


18. What is the difference between synchronous and asynchronous invocation in Lambda?

Feature Synchronous Asynchronous
Caller waits Yes No
Use case API requests, real-time response Background processing, events
Error handling Immediate error response Retry logic handled automatically

19. How does AWS Lambda integrate with other AWS services?

Answer:
Lambda integrates with almost all AWS services. Some examples:

  • S3: Trigger when a file is uploaded

  • DynamoDB Streams: Trigger when a table is updated

  • CloudWatch Events: Run on a schedule (cron jobs)

  • SNS/SQS: Triggered by messages

  • API Gateway: HTTP requests invoke Lambda functions


20. What is a cold start, and how can it be minimized?

Answer:

  • Cold start: Delay when Lambda function initializes a new instance.

  • Warm start: Faster execution because the instance is already running.

Ways to minimize cold starts:

  • Keep functions small in size

  • Avoid large dependencies

  • Provisioned concurrency can keep instances always ready

  • Use lighter languages like Node.js or Python


21. What is the difference between Lambda and Step Functions?

Answer:

  • Lambda: Runs a single function in response to an event.

  • Step Functions: Orchestrates multiple Lambda functions into a workflow, with error handling, retries, and branching.

Use Step Functions for long-running or multi-step processes.


22. Can a Lambda function call another Lambda function?

Answer:
Yes, a Lambda function can invoke another Lambda function either:

  • Synchronously: Waits for a response

  • Asynchronously: Doesn’t wait

This is commonly used in microservices architecture.


23. What is the maximum memory allocation in AWS Lambda?

Answer:

  • Lambda allows memory allocation from 128 MB to 10,240 MB (10 GB).

  • CPU and network throughput scale with memory, so higher memory can make functions faster.


24. Can you run AWS Lambda inside a VPC?

Answer:
Yes, you can configure Lambda to access resources inside a VPC, such as:

  • RDS databases

  • Private subnets

  • Internal APIs

Note: When connecting to a VPC, Lambda needs Elastic Network Interfaces (ENIs), which may increase cold start time slightly.


25. What are the common use cases of AWS Lambda?

Answer:
AWS Lambda is highly versatile and used in:

  1. Data processing: Transforming files in S3, resizing images, processing logs.

  2. Real-time stream processing: Using Kinesis or DynamoDB Streams.

  3. Serverless APIs: Using API Gateway to serve HTTP requests.

  4. Automation tasks: Scheduled jobs using CloudWatch Events.

  5. Microservices: Running independent, small services without managing servers.


26. How do you handle errors in AWS Lambda?

Answer:
Lambda provides multiple ways to handle errors:

  • Retries: Asynchronous invocations automatically retry twice on failure.

  • Dead Letter Queues (DLQ): Failed events can be sent to SQS or SNS.

  • Error handling in code: Use try-except (Python) or try-catch (Java/Node.js).

  • Lambda Destinations: Send success/failure events to other services for monitoring.


27. What is the difference between Lambda and Fargate?

Feature AWS Lambda AWS Fargate
Server Management Fully serverless Serverless containers
Execution Duration Max 15 minutes Can run indefinitely
Use Case Event-driven, short tasks Long-running microservices
Scaling Automatic Automatic with ECS service

28. What are AWS Lambda Layers and how are they versioned?

Answer:

  • Layers let you package libraries, dependencies, and configuration files separately from the function code.

  • Versioning: Each time you update a layer, AWS creates a new version. You can attach a specific version to a Lambda function so updates don’t break your code.


29. Can Lambda write data to a database?

Answer:
Yes! Lambda can connect to databases like RDS, DynamoDB, or Aurora. Best practices:

  • Use IAM roles for permissions.

  • Avoid opening too many connections at once (use connection pooling or RDS Proxy).

  • Ensure Lambda has network access if the database is inside a VPC.


30. What is provisioned concurrency in AWS Lambda?

Answer:

  • Provisioned concurrency keeps a specified number of Lambda instances always warm to avoid cold start delays.

  • Useful for latency-sensitive applications, like real-time APIs.

  • You are billed for the provisioned concurrency even if functions are not running, in addition to actual execution time.


31. How do you test AWS Lambda functions locally?

Answer:

  • Use AWS SAM CLI (Serverless Application Model): Emulates Lambda environment locally.

  • Serverless Framework: Allows running Lambda on your machine.

  • Write unit tests using Python unittest or Node.js jest.

  • Test with mock events like S3 upload events or API Gateway requests.


32. How do you monitor AWS Lambda performance?

Answer:

  • CloudWatch Logs: Logs from every Lambda invocation.

  • CloudWatch Metrics: Provides metrics like Invocations, Duration, Errors, Throttles.

  • AWS X-Ray: Helps trace requests across multiple Lambda functions and services.

  • Third-party tools: Datadog, New Relic, etc. for advanced monitoring.


33. What are Lambda function triggers and event sources?

Answer:

  • Trigger/Event source: AWS service that invokes Lambda.

  • Examples:

    • S3 – file upload

    • DynamoDB Streams – table updates

    • SNS/SQS – messages

    • CloudWatch Events – scheduled tasks

    • API Gateway – HTTP requests


34. Can a Lambda function run for more than 15 minutes?

Answer:
No, Lambda has a maximum execution limit of 15 minutes per invocation.
Solution for longer tasks:

  • Split the task into smaller chunks.

  • Use AWS Step Functions to orchestrate multiple Lambda functions.

  • Offload to Fargate or EC2 for long-running processes.


35. What is the difference between synchronous and asynchronous invocations in Lambda?

Feature Synchronous (Request-Response) Asynchronous
Caller waits Yes No
Error handling Immediate response to caller Retries automatically
Use cases API calls, real-time responses Event processing (S3, SNS)

36. How do you secure AWS Lambda functions?

Answer:

  • IAM Roles: Least-privilege permissions for Lambda.

  • VPC: Restrict Lambda access to private resources.

  • KMS Encryption: Encrypt environment variables or sensitive data.

  • Trigger Restrictions: Only allow trusted sources to invoke Lambda.

  • Code Security: Avoid hardcoding secrets; use Secrets Manager.


37. What is the role of AWS API Gateway with Lambda?

Answer:

  • API Gateway acts as an HTTP interface for Lambda.

  • Allows you to create RESTful or WebSocket APIs without managing servers.

  • Integrates with Lambda for request/response mapping.

  • Supports authentication, throttling, caching, and monitoring.


38. How is AWS Lambda billed?

Answer:
Lambda billing is based on two factors:

  1. Number of requests: First 1 million requests per month are free; after that, you pay per request.

  2. Duration of execution: Based on memory allocated and execution time (in milliseconds).

Example:

  • Memory: 512 MB

  • Execution time: 1 second

  • You pay for 1 second × 512 MB usage


39. What are Lambda destinations and when are they used?

Answer:

  • Lambda Destinations allow you to send the result of an asynchronous Lambda execution to another service.

  • Success destination: Triggered when function executes successfully

  • Failure destination: Triggered when function fails

  • Services used: SNS, SQS, EventBridge, or another Lambda


40. How do you optimize Lambda function performance?

Answer:

  • Minimize deployment package size.

  • Reduce cold starts (smaller code, provisioned concurrency).

  • Reuse database connections (connection pooling or RDS Proxy).

  • Avoid long-running loops or blocking calls.

  • Monitor with CloudWatch and X-Ray to find bottlenecks.


 

Experienced Interview Questions

 

1. What is AWS Lambda and what are its main benefits?

Answer:
AWS Lambda is a serverless compute service that lets you run code without provisioning or managing servers. You upload your code (as a function), and Lambda executes it only when triggered by events.

Key Benefits:

  • No server management: AWS handles scaling, patching, and infrastructure.

  • Automatic scaling: Lambda can automatically scale depending on the number of events.

  • Cost-efficient: You pay only for the compute time used (per 1ms).

  • Event-driven architecture: Integrates with services like S3, DynamoDB, API Gateway, CloudWatch, etc.

  • Microservices support: Perfect for small, decoupled services.

Example for experience-level demonstration:
"At my previous job, we used Lambda to process images uploaded to S3. Each upload triggered a Lambda function to resize images, saving us from managing servers and scaling issues."


2. What are the different ways to invoke a Lambda function?

Answer:
Lambda functions can be invoked in three ways:

  1. Synchronous Invocation:

    • The caller waits for the function to process and return a response.

    • Example: API Gateway calling Lambda to return a response to a user request.

  2. Asynchronous Invocation:

    • The caller doesn’t wait for a response; Lambda retries if it fails.

    • Example: S3 event triggers Lambda after a file upload.

  3. Event Source Mapping (Poll-based invocation):

    • Lambda polls certain services like SQS, DynamoDB Streams, or Kinesis and invokes the function when there’s a new event.

Pro Tip: Mention retries, dead-letter queues (DLQ), and error handling in real scenarios.


3. How do you manage dependencies and package size in Lambda?

Answer:
Lambda has a deployment package size limit of 50 MB (ZIP) and 250 MB (uncompressed with layers). Managing dependencies is crucial for performance.

Ways to manage dependencies:

  • Lambda Layers: Share libraries across multiple functions.

  • Package only what is needed: Avoid including unnecessary libraries.

  • Use Amazon EFS: For large libraries or datasets (Lambda can mount EFS).

  • Container Images: Lambda supports Docker images up to 10 GB.

Experience-level note:
"For a Python-based Lambda, I moved the pandas and numpy libraries to a Lambda Layer to reduce cold start time and keep the deployment package small."


4. What are cold starts and how can you reduce them?

Answer:
Cold start: The first invocation of a Lambda function requires initializing the execution environment, which can add latency (usually 100ms–1s for typical functions, longer for Java or large packages).

Ways to reduce cold starts:

  • Keep functions lightweight: Smaller deployment packages.

  • Use provisioned concurrency: Keeps a specified number of instances ready to respond instantly.

  • Use compatible runtimes: Python or Node.js cold starts are generally faster than Java or .NET.

  • Avoid VPC if not needed: Lambda inside VPC takes longer unless using AWS Lambda VPC ENIs improvements.

Example from experience:
"We enabled provisioned concurrency for our payment processing Lambda, which reduced cold start latency from 1.2 seconds to 150ms."


5. How do you handle error handling and retries in AWS Lambda?

Answer:
Error handling strategies:

  • Try-catch blocks inside the function for predictable errors.

  • Dead Letter Queue (DLQ): SQS or SNS queue to capture failed events.

  • Retries:

    • Synchronous: No automatic retry; handle manually.

    • Asynchronous: Lambda retries twice by default.

    • Event source mapping: SQS, Kinesis, and DynamoDB Streams have their own retry policies.

Advanced note:

  • Use Lambda Destinations for success and failure outcomes to redirect events automatically.


6. How does Lambda integrate with other AWS services?

Answer:
AWS Lambda is event-driven and integrates with most AWS services:

  • S3: Trigger Lambda on file upload or deletion.

  • DynamoDB Streams: Process data changes.

  • API Gateway: Serve HTTP requests.

  • SNS/SQS: Event notifications and messaging.

  • CloudWatch Events/ EventBridge: Scheduled events or system events.

  • Step Functions: Coordinate multiple Lambdas into workflows.

Pro Tip for experience-level answer:
"We used Lambda with Step Functions to orchestrate multi-step data processing pipelines, ensuring each step executed reliably and errors were handled automatically."


7. How do you secure AWS Lambda functions?

Answer:

  • IAM Roles: Assign least privilege roles to Lambda.

  • VPC: Place Lambda in a VPC for private resource access.

  • Environment Variables Encryption: Use AWS KMS to encrypt sensitive data.

  • API Gateway authorizers: Use JWT or Lambda authorizers for APIs.

  • Resource-based policies: Control which services or accounts can invoke Lambda.

Example:
"We encrypted database passwords in Lambda environment variables using KMS and ensured only the Lambda role could decrypt them."


8. How do you monitor and optimize Lambda performance?

Answer:

  • Monitoring:

    • CloudWatch Logs and Metrics for invocation count, duration, errors, and throttles.

    • X-Ray for tracing requests and identifying bottlenecks.

  • Optimization:

    • Right-size memory (more memory = more CPU).

    • Reduce package size and cold start impact.

    • Optimize code for performance, avoid unnecessary network calls.

Experience-level tip:
"We used CloudWatch and X-Ray to identify a Lambda that was spending 80% of its time waiting on S3, so we introduced asynchronous S3 read optimizations."


9. What are best practices for AWS Lambda development?

Answer:

  • Keep functions single-purpose.

  • Use environment variables for config.

  • Implement timeouts to avoid runaway executions.

  • Handle errors gracefully.

  • Use layers for dependencies.

  • Test locally using SAM CLI or localstack.

  • Enable logging and monitoring.

  • Minimize cold starts (provisioned concurrency if needed).


10. Can you describe a real-world scenario where you used Lambda in a production system?

Answer (experience-oriented):
"In a project, we used AWS Lambda to automate processing of images uploaded by users to S3. Each image upload triggered a Lambda function that resized the image, applied a watermark, and saved it to another bucket. We used CloudWatch for monitoring, Lambda Layers for dependencies, and Step Functions to chain multiple processing steps. This reduced processing time by 60% compared to our previous EC2-based system and removed the need for server maintenance."


Perfect! Since you want more AWS Lambda questions and answers for a 4-year experienced level, I’ll give you 15 advanced questions that focus on real-world scenarios, troubleshooting, architecture, and best practices. Each answer will be detailed so you can explain confidently in an interview.


11. What is the difference between Lambda and EC2? When would you choose Lambda over EC2?

Answer:

  • EC2: Full server you manage; persistent; you handle OS, scaling, patching.

  • Lambda: Serverless; runs code on-demand; auto-scaling; pay-per-use.

Choose Lambda when:

  • Event-driven workloads (e.g., S3 uploads, API Gateway calls).

  • Short-lived, stateless tasks.

  • Don’t want to manage servers or auto-scale manually.

Experience-level example:
"We used Lambda for image processing triggered by S3 because the workload was spiky and short-lived. EC2 would have been idle most of the time."


12. What are Lambda layers and why would you use them?

Answer:

  • Lambda Layer: A zip archive with libraries or custom code that can be shared across multiple functions.

  • Benefits:

    • Reduce deployment package size.

    • Share common dependencies.

    • Easier to update code libraries without redeploying the function.

Example:
"We moved pandas, numpy, and custom utilities into a layer to keep deployment packages under 50 MB and reduce cold start times."


13. Explain the Lambda execution model and lifecycle.

Answer:

  • Request received → Execution environment created (cold start if new) → Handler invoked → Execution environment frozen (if idle) → Reused for subsequent invocations (warm start).

  • Cold start: Environment creation + dependency loading.

  • Warm start: Environment reused; faster execution.

Experience tip:
"We noticed that Java Lambdas had 1–2s cold starts, so we used provisioned concurrency for critical paths."


14. How does Lambda pricing work?

Answer:
Pricing is based on:

  1. Number of requests: $0.20 per 1 million requests (as of 2025).

  2. Duration: Time function runs (in milliseconds) × allocated memory.

  3. Provisioned concurrency: If enabled, pay for pre-warmed instances.

Experience tip:
"We optimized cost by right-sizing memory; increasing memory reduced execution time and overall cost."


15. What are the timeout limits for Lambda and how do you choose them?

Answer:

  • Maximum timeout is 15 minutes per execution.

  • Default is 3 seconds.

  • Set timeout based on expected function runtime plus buffer.

Experience-level example:
"A video processing Lambda needed 10 minutes; we set timeout to 12 minutes to handle occasional larger files."


16. How do you troubleshoot Lambda failures?

Answer:

  • CloudWatch Logs: Check invocation logs.

  • CloudWatch Metrics: Monitor errors, throttles, duration.

  • AWS X-Ray: Trace request flow and find bottlenecks.

  • DLQ or Lambda Destinations: Capture failed events.

  • Common issues: Permission errors (IAM), timeout, memory shortage, dependency errors.


17. How do you invoke Lambda from API Gateway?

Answer:

  • REST API: Map HTTP requests to Lambda.

  • Lambda Proxy Integration: API Gateway passes entire request to Lambda; Lambda returns HTTP response.

  • Security: Use IAM roles, API keys, or authorizers (Cognito/JWT).

Experience tip:
"We used Lambda Proxy integration to handle dynamic POST requests and return JSON responses directly."


18. What is Provisioned Concurrency vs Reserved Concurrency?

Answer:

  • Provisioned Concurrency: Keeps pre-warmed instances ready; reduces cold starts.

  • Reserved Concurrency: Guarantees maximum number of concurrent executions; helps prevent throttling.

Experience example:
"We set provisioned concurrency for user login Lambda to reduce latency, and reserved concurrency for a batch job to avoid affecting other functions."


19. How do you handle large payloads in Lambda?

Answer:

  • Direct invocation payload limit: 6 MB (synchronous), 256 KB (asynchronous).

  • Workarounds for large data:

    • Store payload in S3 and pass S3 object reference.

    • Use streaming for Kinesis or DynamoDB events.

    • Use API Gateway + S3 integration for uploads.


20. How do you handle state in serverless architecture?

Answer:

  • Lambda is stateless. State can be maintained using:

    • DynamoDB: Key-value storage.

    • S3: Store files or serialized objects.

    • ElastiCache (Redis): Temporary state for sessions.

    • Step Functions: Orchestrates stateful workflows.

Example:
"We used DynamoDB to track order processing state across multiple Lambda executions."


21. How do you optimize Lambda performance?

Answer:

  • Increase memory (CPU scales with memory).

  • Reduce package size.

  • Avoid VPC if not required.

  • Use async calls for external services.

  • Use layers to share dependencies.

  • Enable provisioned concurrency for latency-sensitive functions.


22. How do you secure Lambda functions in production?

Answer:

  • Use IAM roles with least privilege.

  • Encrypt environment variables with KMS.

  • Use VPC for private access.

  • Enable logging and monitoring.

  • Use resource-based policies for cross-account invocations.


23. What are Lambda Destinations and why use them?

Answer:

  • Sends the result of an asynchronous Lambda invocation to another AWS service:

    • Success destination: SNS, SQS, Lambda, EventBridge.

    • Failure destination: Capture failed events for retries or alerts.

  • Helps with error handling and decoupling workflows.

Example:
"We used a failure destination to send failed events to SQS, which our team processed later."


24. What is the maximum concurrency Lambda can handle?

Answer:

  • By default, 1,000 concurrent executions per region (can request a quota increase).

  • Reserved concurrency can reserve capacity for critical functions.

  • Provisioned concurrency pre-warms instances for high-performance use cases.


25. How do you deploy Lambda in a CI/CD pipeline?

Answer:

  • Use AWS SAM, Serverless Framework, or Terraform for Infrastructure as Code.

  • Steps:

    1. Build and test locally.

    2. Package Lambda with dependencies.

    3. Deploy using CloudFormation/SAM/Serverless CLI.

    4. Integrate with CodePipeline or GitHub Actions.

  • Can use blue/green or canary deployments with Lambda + API Gateway.