Study Guide850 words

AWS Lambda Deployment Packaging Options

Describe Lambda deployment packaging options

AWS Lambda Deployment Packaging Options

When deploying code to AWS Lambda, developers must choose a packaging format that aligns with their application size, dependency complexity, and existing CI/CD workflows. This guide covers the two primary methods: Zip file archives and Container images.


Learning Objectives

By the end of this guide, you should be able to:

  • Differentiate between .zip file archives and OCI-compliant container images.
  • Identify the size limitations and storage requirements for each packaging type.
  • Explain how Lambda Layers optimize .zip deployments.
  • Select the appropriate packaging method based on technical requirements.

Key Terms & Glossary

  • Deployment Package: A bundle containing your function code and its dependencies.
  • Zip File Archive: The traditional Lambda packaging format where code and libraries are compressed into a single .zip file.
  • Container Image: A package formatted as an OCI-compliant image (e.g., Docker) stored in Amazon ECR.
  • Lambda Layer: A distribution mechanism for libraries, custom runtimes, and other function dependencies.
  • Amazon ECR: Elastic Container Registry; the required storage service for Lambda container images.
  • Runtime Interface Client (RIC): A component required in custom container images to communicate with the Lambda Runtime API.

The "Big Idea"

AWS Lambda is "serverless," but the underlying infrastructure still needs a structured way to receive and execute your code. Think of packaging as choosing the shipping container for your application. If your app is small and uses standard libraries, a Zip file is like a standard parcel. If your app is massive (like a Machine Learning model) or relies on complex system-level dependencies, a Container Image is the heavy-duty shipping crate that ensures everything arrives and runs exactly as it did on your local machine.


Formula / Concept Box

Feature.zip File ArchiveContainer Image
Max Size50 MB (zipped direct), 250 MB (unzipped)10 GB
Storage ServiceAmazon S3 (internal)Amazon ECR
Dependency ReuseUse Lambda LayersUse Multi-stage Docker Builds
Best ForSimple scripts, rapid iterationLarge apps, ML models, Docker-centric teams
ToolingConsole, CLI, SAM, CDKDocker, Buildah, ECR CLI, SAM

Hierarchical Outline

  • I. .zip File Archives
    • Standard Method: Most common for simple logic.
    • Structure: Code at the root, dependencies in folders.
    • Lambda Layers:
      • Promotes code reuse across functions.
      • Up to 5 layers per function.
  • II. Container Images
    • OCI Compliance: Must follow Open Container Initiative standards.
    • Requirements: Must include a Runtime Interface Client (RIC).
    • Scalability: Allows for large binaries (up to 10GB).
  • III. Choosing a Strategy
    • Size Constraint: If > 250MB (unzipped), use Container Images.
    • Environment Control: If specific OS libraries are needed, use Containers.

Visual Anchors

Packaging Decision Flow

Loading Diagram...

Lambda Layer Architecture

\begin{tikzpicture}[node distance=2cm, every node/.style={fill=white, font=\small}] \draw[thick, fill=blue!10] (-2,-0.5) rectangle (6,4); \node at (2, 3.5) {\textbf{AWS Lambda Environment}};

code
% Function Logic \node[draw, rectangle, fill=green!20] (func) at (0,2) {Function Code}; % Layers \node[draw, rectangle, fill=orange!20] (layer1) at (4,2.5) {Layer 1: NumPy}; \node[draw, rectangle, fill=orange!20] (layer2) at (4,1.5) {Layer 2: Custom Lib}; % Arrows \draw[->, thick] (layer1) -- (func); \draw[->, thick] (layer2) -- (func); \node[below] at (2,-0.5) {Layers are extracted to /opt/ during execution};

\end{tikzpicture}


Definition-Example Pairs

  • Lambda Layer: A way to pull in code from a separate package into your function at runtime.
    • Example: A company creates a "SecurityUtils" layer containing standard encryption logic used by 50 different Lambda functions.
  • Runtime Interface Client (RIC): An adapter that allows a containerized application to communicate with the AWS Lambda service.
    • Example: You use an Alpine Linux base image and must install the aws-lambda-ric package via npm or pip to make it Lambda-compatible.
  • Unzipped Size Limit: The total size of the function code plus all its layers once decompressed.
    • Example: If your .zip is 40MB but expands to 260MB, the deployment will fail because it exceeds the 250MB limit.

Worked Examples

Scenario 1: Small Python Web Scraper

  • Need: A script using requests and beautifulsoup4.
  • Solution: .zip file archive.
  • Steps:
    1. Install dependencies locally: pip install requests -t .
    2. Zip the folder contents: zip -r function.zip .
    3. Upload via AWS CLI: aws lambda update-function-code --function-name MyScraper --zip-file fileb://function.zip.

Scenario 2: Image Processing with OpenCV

  • Need: Large binary libraries (OpenCV) and a 400MB pre-trained model.
  • Solution: Container Image.
  • Steps:
    1. Create a Dockerfile using the AWS Lambda Python base image.
    2. COPY the model and code into the image.
    3. Build and push to ECR: docker push <account>.dkr.ecr.<region>.amazonaws.com/my-lambda-image:latest.
    4. Point the Lambda function to the ECR Image URI.

Checkpoint Questions

  1. What is the maximum size for a Lambda function package using the Container Image format?
  2. True or False: Lambda Layers can be used with Container Image deployments.
  3. Where is the unzipped code and layer content located within the Lambda execution environment filesystem?
  4. Which AWS service is mandatory for storing Lambda-compatible container images?
Click to see answers
  1. 10 GB.
  2. False (Layers are only for .zip archives; containers use Docker layers).
  3. In the /opt directory (for layers) and /var/task (for code).
  4. Amazon Elastic Container Registry (ECR).

Ready to study AWS Certified Developer - Associate (DVA-C02)?

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

Start Studying — Free