Ravindra BagaleCourses & study guides मराठी

Chapter 93: AWS Lambda and Serverless for DevOps

DevOps

93.9 Dependencies, ZIP packages and layers

Story (fictional teaching scenario). At a fictional Patna shop, Nina from Berlin installs a library on her laptop but forgets to package it. The cloud runtime cannot import it.

Dependencies, ZIP packages and layers
Dependencies, ZIP packages and layers

Why

Your laptop’s packages do not automatically travel with the function.

What

  • Dependency is a library your code imports.
  • ZIP package contains the handler and dependencies; the handler file must be at its expected root path.
  • Layer is a separately versioned ZIP of reusable libraries/content mounted into the environment. A Python layer uses a python/ folder. Layers do not apply to a function packaged as a container image.
  • Native dependency contains compiled code; it must match the Linux runtime and CPU architecture.
  • Container image package is another packaging option, not an always-running ECS service.

How

  1. Start with standard-library-only code in this local lab.

  2. Pin and test dependencies for the target runtime.

  3. Keep ZIP/layer paths correct.

  4. Rebuild image-based functions when dependencies or base images need updates.

Example 1: Make a local ZIP without any AWS call

  1. Read the input and the code.
python3 -m zipfile -c price.zip price.py
python3 -m zipfile -l price.zip
  1. Read the result.

Output (illustrative; not executed on AWS)

File Name ...
price.py ...
  1. What each part means: The first command creates an archive of just the handler. The second lists its entries. The root contains price.py, not an extra parent folder. No upload occurs. Exact dates and sizes vary.

Example 2: Layer layout

  1. Read the input and the code.
layer.zip
  python/
    shared_rules.py
  1. Read the result.

Output (illustrative; not executed on AWS)

Import path in the function: import shared_rules
  1. What each part means: The Python folder is the required package layout. A layer version is immutable; changing a shared library means publishing a new layer version and deliberately updating consumers. This is a layout illustration, not a layer creation.

Ravindra Bagale's Tip

Small packages make startup and security review easier.

Did you understand? Let us try it once more.