How to centrally share and update Python code across many Lambda functions?

Answer Correct answer: B — Package the custom Python scripts into a Lambda layer and attach that layer to each function so one layer update replaces editing every function.

A data engineer maintains custom Python scripts that perform a data formatting process that many AWS Lambda functions use. When the data engineer needs to modify the Python scripts, the data engineer must manually update all the Lambda functions. The data engineer requires a less manual way to update the Lambda functions. Which solution will meet this requirement?

  1. Store a pointer to the custom Python scripts in the execution context object in a shared Amazon S3 bucket.
  2. Package the custom Python scripts into Lambda layers. Apply the Lambda layers to the Lambda functions. Correct Answer
  3. Store a pointer to the custom Python scripts in environment variables in a shared Amazon S3 bucket.
  4. Assign the same alias to each Lambda function. Call reach Lambda function by specifying the function's alias.

Community Votes

B
100%

100% of anonymous learners picked answer B. Votes are pick records left by other test-takers — they are not the verified answer.

Community Insight

The test is on reusing shared code across multiple Lambda functions; the trap is confusing function-level configuration (environment variables, aliases) with a deployable shared code artifact.

Lambda layers let you package shared Python code once and attach it to many Lambda functions, so a single layer update replaces editing every function. This page confirms option B as the answer and explains why S3 pointers, environment variables, and aliases do not deliver centralized code management.

Choosing the environment-variable or S3-pointer options, because they sound like 'configuration' — but each function still needs its own env var set and its own download logic, which repeats exactly the manual editing work the engineer is trying to eliminate.

Community Discussion (9 comments)

TonyStark0122 👍 20
B. Package the custom Python scripts into Lambda layers. Apply the Lambda layers to the Lambda functions. Explanation: Lambda layers allow you to centrally manage shared code and dependencies across multiple Lambda functions. By packaging the custom Python scripts into a Lambda layer, you can simply update the layer whenever changes are made to the scripts, and all the Lambda functions that use the layer will automatically inherit the updates. This approach reduces manual effort and ensures consistency across the functions.
pypelyncar 👍 4 Selected: B
Centralized Code Management: Lambda layers allow you to store and manage the custom Python scripts in a central location outside the individual Lambda function code. This eliminates the need to update the script in each Lambda function manually. Reusable Code: Layers provide a way to share code across multiple Lambda functions. Any changes made to the layer code are automatically reflected in all the functions using that layer, streamlining updates. Reduced Deployment Size: By separating core functionality into layers, you can keep the individual Lambda function code focused and smaller. This reduces deployment package size and potentially improves Lambda execution times.
JavierEF 👍 2 Selected: B
Lambda Layers is a feature created with this literal objective in mind.
John2025 👍 2
B is right
4c78df0 👍 1 Selected: B
B is correct
4c78df0 👍 1 Selected: B
B is correct
FunkyFresco 👍 1 Selected: B
Lamba layers
ba72eb9 👍 2
Option B
kj07 👍 2
Typical use case for Lambda Layers. Option B.

Comments & Corrections

No comments yet — spotted an error or have a note? Share it below.

Log in to comment, report an error, or add a note about this question.

Submitted for moderation before publishing. Keep it helpful and respectful.

Expert Analysis

Why the Answer Is Correct

Lambda layers are the purpose-built mechanism for sharing code and dependencies between functions: you package the formatting script into a layer once and reference that layer from every function. When the script changes, you publish a new layer version and update the layer reference instead of editing each function's inline code, which removes the manual duplication described in the scenario. The layer is also versioned and immutable, so each function can pin a known-good version while a newer one is rolled out and tested. This is exactly the use case AWS documents for layers, which is why option B is the only one that changes the deployment artifact rather than the per-function settings.

Why the Other Options Are Wrong

Option A invents a capability: the execution context object is runtime-internal and cannot be used as a configuration store, and pointing at code in S3 still forces every function to fetch and execute it at invocation time with its own IAM permissions and latency. Option C fails for the same reason plus the duplication problem — environment variables are set per function, so changing the script means editing every function's environment, and the 4 KB limit plus lack of versioning makes it unsuitable for code. Option D misuses aliases, which are pointers to versions of a single function for traffic shifting and stable invocation ARNs; they do nothing to share Python code between different functions.

Community Comment Notes

TonyStark0122 summarized the mechanics well, noting that layers "allow you to centrally manage shared code and dependencies across multiple Lambda functions." pypelyncar added the key benefit that a layer is stored in a central location outside the individual function code, and JavierEF put it bluntly that Lambda Layers is "a feature created with this literal objective in mind." kj07 called it a typical Lambda Layers use case, and the unanimous vote record (B: 100) matches that consensus. One nuance worth carrying into the exam: layer versions are immutable, so "automatic" update means publishing a new version and repointing functions — still one artifact to maintain instead of many scripts.

Official Reference

Exam Strategy

When a question says code or libraries are duplicated across several Lambda functions and must be updated with less manual effort, the answer is almost always Lambda layers. Rule out any option that stores a 'pointer' in environment variables, execution context, or S3, since those still require per-function edits.

Frequently Asked Questions

Why not store the shared Python scripts in S3 and reference them from environment variables?

Every function would still need its own environment variable and download logic, adding cold-start latency and S3 permissions without any central, versioned code artifact.

Do Lambda layer changes apply automatically to functions already using the layer?

No. Layer versions are immutable, so you publish a new version and repoint the functions (or reference $LATEST), which can be scripted via the Lambda API or IaC.

More DEA-C01 FAQ →

Related Analysis

Practice All DEA-C01 Questions

Access 100 questions with complete answers and detailed explanations.

View Full DEA-C01 Practice Test →

← Back to DEA-C01 Study Guide