Day 11: AWS | Lambda (Serverless)

Day 11: AWS | Lambda (Serverless)

What is AWS Lambda?

  • AWS Lambda is a compute service that runs your code in response to events and automatically manages the compute resources, making it the fastest way to turn an idea into a modern, production, serverless applications.

  • Lambda has two primary characteristics compute and serverless.

  • But lambda solves the problem of serverless.

  • Primary difference between EC2 and Lambda is lambda follows the serverless architecture.

  • If you are spinning up the a lambda function you will not provide all of details to EC2.

  • AWS automatically take care of the server depending upon the application that you are running.

  • Once the job is done aws will tear down the compute whereas that is not in case of EC2.

Who will decide should we go with serverless approach and server approach?

  • This will be taken care by development team, architecture and design team, they will decide which approach you have to choose.

Why we need serverless when we have already EC2?

  1. Simplified Management:

    • Serverless platforms abstract away the underlying infrastructure, eliminating the need for users to manage servers, networking, or storage. This makes it easier for developers to focus on writing code rather than dealing with infrastructure management tasks.
  2. Automatic Scaling:

    • Serverless platforms automatically scale based on demand. With EC2, you often need to manage the scaling of instances manually or use auto-scaling groups, which may require more configuration and monitoring.
  3. Cost Efficiency:

    • Serverless functions are billed based on actual usage, measured in milliseconds, and typically have a free tier for a certain level of usage. EC2 instances require ongoing costs, even if the server is idle, and users are billed based on the instance type and running time.
  4. Event-Driven Architecture:

    • Serverless is well-suited for event-driven architectures where functions are triggered by specific events, such as HTTP requests, database changes, or file uploads. EC2 instances, on the other hand, are typically running continuously and may not be as inherently designed for event-driven workflows.
  5. Faster Deployment:

    • Serverless applications are usually quicker to deploy as there is no need to provision or configure servers. Developers can focus on writing code and deploy it without worrying about the infrastructure setup.
  6. Microservices Architecture:

    • Serverless can be beneficial in a microservices architecture where each function can represent a specific microservice. This allows for a more modular and scalable application design.
  7. Low-latency and Stateless Operations:

    • For short-lived, stateless operations, serverless functions can be more suitable. They start quickly, execute the code, and then stop, making them efficient for tasks that don't require persistent server instances.

Note:

  • While serverless has these advantages, EC2 instances continue to be important for certain use cases, especially when there is a need for more control over the underlying infrastructure, long-running processes, or specific configurations that are not well-suited for the stateless nature of serverless functions. Ultimately, the choice between serverless and EC2 depends on the specific requirements and characteristics of the application you are building.