Study Guide820 words

AWS Serverless Technologies: Lambda and Fargate

Serverless technologies and patterns (for example, AWS Fargate, AWS Lambda)

AWS Serverless Technologies: Lambda and Fargate

Learning Objectives

After studying this guide, you should be able to:

  • Distinguish between the serverless compute models of AWS Lambda and AWS Fargate.
  • Identify appropriate use cases for serverless architectures versus traditional EC2-based environments.
  • Explain how serverless technologies facilitate decoupled and event-driven architectures.
  • Select the correct resource configurations (e.g., Lambda memory) to meet performance and budget requirements.
  • Understand the role of orchestration services like Amazon ECS/EKS in conjunction with Fargate.

Key Terms & Glossary

  • Serverless: A cloud computing execution model where the provider manages the allocation of machine resources, allowing developers to focus on code without managing servers.
  • AWS Lambda: A function-as-a-service (FaaS) that runs code in response to events and automatically manages the underlying compute resources.
  • AWS Fargate: A serverless compute engine for containers that works with Amazon ECS and EKS, removing the need to provision and manage servers.
  • Event-Driven Architecture: A software architecture pattern where the flow of the program is determined by events (e.g., file uploads, database changes, or sensor outputs).
  • Statelessness: A design principle where the server does not store any client session data; each request is independent. Serverless functions are inherently stateless.

The "Big Idea"

The "Big Idea" behind serverless is the abstraction of infrastructure. In traditional computing, you manage the "box" (server). In serverless, you only manage the "logic" (Lambda) or the "package" (Fargate containers). This allows for near-infinite horizontal scaling and a "pay-only-for-what-you-use" cost model, shifting the focus from maintenance to innovation.

Formula / Concept Box

FeatureAWS LambdaAWS Fargate
Unit of ScaleSingle FunctionContainer (Task/Pod)
Timeout Limit15 MinutesNo hard limit (Long-running)
ManagementCode onlyContainer image + Orchestration
BillingPer request & durationPer vCPU and GB per hour
ScalingInstantaneous, event-basedFast, based on CPU/RAM metrics

Hierarchical Outline

  • Serverless Compute Options
    • AWS Lambda (Function-as-a-Service)
      • Triggers: S3, DynamoDB, API Gateway, SQS, CloudWatch.
      • Configuration: Primarily memory (CPU scales linearly with memory).
      • Execution: Ephemeral environments; max 15 mins.
    • AWS Fargate (Container-as-a-Service)
      • Orchestrators: ECS (Elastic Container Service) or EKS (Kubernetes).
      • Benefits: No EC2 instances to manage, patch, or scale manually.
  • Serverless Architecture Patterns
    • Event-Driven: Components communicate via events (e.g., S3 \rightarrow Lambda).
    • Decoupled: Using Amazon SQS or SNS to ensure components scale independently.
    • Orchestration: Using AWS Step Functions to manage complex workflows involving multiple Lambda functions.
  • API Management
    • Amazon API Gateway: The front door for serverless apps, handling REST/WebSocket APIs.

Visual Anchors

Serverless Web Backend Flow

Loading Diagram...

Compute Technology Spectrum

\begin{tikzpicture}[node distance=2cm, every node/.style={draw, rectangle, rounded corners, inner sep=5pt, text width=2.5cm, align=center}] \node (ec2) {EC2$High Control)}; \node (ecs) [right of=ec2, xshift=1.5cm] {ECS/EKS$Containers)}; \node (fargate) [right of=ecs, xshift=1.5cm] {Fargate$Serverless Containers)}; \node (lambda) [right of=fargate, xshift=1.5cm] {Lambda$Serverless Functions)};

\draw[->, thick] (ec2) -- (ecs); \draw[->, thick] (ecs) -- (fargate); \draw[->, thick] (fargate) -- (lambda);

\node[draw=none, below of=fargate, yshift=1cm, text width=8cm] {\textbf{Increasing Abstraction \rightarrow}\ \textbf{Decreasing Management Overhead \rightarrow}\}; \end{tikzpicture}

Definition-Example Pairs

  • Decoupling: The process of separating components so they do not depend on each other's immediate availability.
    • Example: An ordering system where a website puts an order into an SQS queue, and a Lambda function processes it later. If the Lambda fails, the order is still safe in the queue.
  • Microservices: Small, independent services that communicate over well-defined APIs.
    • Example: A banking app where "Check Balance," "Transfer Funds," and "Pay Bills" are all separate Lambda functions.
  • Cold Start: The delay that occurs when a serverless function is triggered after being idle.
    • Example: A rarely used Lambda function taking 2 seconds to respond because AWS has to provision the container environment from scratch.

Worked Examples

Scenario: Image Processing Pipeline

Problem: A social media company needs to resize images uploaded by users. The load is unpredictable (spiky).

Step-by-Step Solution:

  1. Storage: Create an S3 Bucket for uploads.
  2. Trigger: Configure an S3 Event Notification to trigger whenever a .jpg is uploaded.
  3. Compute: Write a Lambda Function using an image library (like Sharp or Pillow).
  4. Execution: The Lambda function pulls the image from S3, resizes it, and saves the thumbnail to a different S3 bucket.
  5. Optimization: Set the Lambda memory to 512MB to balance processing speed with cost.

Scenario: Migrating a Legacy Java App

Problem: A company has a complex Java application running in a Docker container that takes 20 minutes to process data. Lambda's 15-minute limit is too short.

Solution:

  • Use AWS Fargate with Amazon ECS.
  • Since Fargate has no timeout limit and supports standard Docker containers, the application can be migrated with minimal code changes while still benefiting from serverless scaling.

Checkpoint Questions

  1. What is the maximum execution time for an AWS Lambda function?
  2. Which service is best suited for running a serverless Kubernetes cluster?
  3. How does AWS Lambda handle increased demand (scaling)?
  4. Name two AWS services that can be used to decouple serverless components.
  5. If you need full control over the underlying operating system and kernel, should you use Lambda, Fargate, or EC2?
Click to see answers
  1. 15 minutes.
  2. Amazon EKS with the Fargate launch type.
  3. By scaling horizontally, launching more concurrent instances of the function.
  4. Amazon SQS (Queues) and Amazon SNS (Pub/Sub).
  5. EC2.

Ready to study AWS Certified Solutions Architect - Associate (SAA-C03)?

Practice tests, flashcards, and all study notes — free, no sign-up needed.

Start Studying — Free