How to centrally share and update Python code across many Lambda functions?
Short 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.
Question
Key Takeaways
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.
Common mistake: 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.
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
https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html
This link opens the official vendor documentation in a new tab.
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?
Do Lambda layer changes apply automatically to functions already using the layer?
Community Votes
100% of anonymous learners picked answer B. Votes are pick records left by other test-takers — they are not the verified answer.
Discussion 8 contributions
Compiled from public community threads and reader submissions, lightly edited for clarity. Handles and vote tallies are shown as recorded, and comments reflect the views of individual contributors.
From public community threads 8
-
TonyStark0122 👍 20B. 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 Answered BCentralized 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 Answered BLambda Layers is a feature created with this literal objective in mind.
-
kj07 👍 2Typical use case for Lambda Layers. Option B.
-
John2025 👍 2B is right
Show 3 more comments
-
ba72eb9 👍 2Option B
-
4c78df0 👍 1 Answered BB is correct
-
FunkyFresco 👍 1 Answered BLamba layers
Reader comments & corrections
No reader corrections yet — spotted an error or have a note? Share it below.
Related Analysis
Practice All DEA-C01 Questions
Access 100 questions with complete answers and detailed explanations.
View Full DEA-C01 Practice Test →