DVA-C02 · Question #487
A developer created reusable code that several AWS Lambda functions need to use. The developer bundled the code into a zip archive. The developer needs to deploy the code to AWS and update the Lambda
The correct answer is C. Create a Lambda layer that contains the zip archive. Attach the Lambda layer to the Lambda. Lambda Layers are the purpose-built feature for packaging and sharing reusable code across multiple Lambda functions without bundling it into each individual deployment package.
Question
A developer created reusable code that several AWS Lambda functions need to use. The developer bundled the code into a zip archive. The developer needs to deploy the code to AWS and update the Lambda functions to use the code. Which solution will meet this requirement in the MOST operationally efficient way?
Options
- AUpload the zip archive to Amazon S3. Configure an import path on the Lambda functions to point
- BCreate a new Lambda function that contains and runs the shared code. Update the existing
- CCreate a Lambda layer that contains the zip archive. Attach the Lambda layer to the Lambda
- DCreate a Lambda container image that includes the shared code. Use the container image as a
How the community answered
(24 responses)- A17% (4)
- B8% (2)
- C71% (17)
- D4% (1)
Why each option
Lambda Layers are the purpose-built feature for packaging and sharing reusable code across multiple Lambda functions without bundling it into each individual deployment package.
Lambda functions do not support an 'import path' configuration pointing to S3 for shared code; code must be included in the deployment package or provided via a layer.
Creating a separate Lambda function to run shared code introduces network latency, additional invocation costs, and error-handling complexity compared to a layer that runs in the same execution environment.
A Lambda layer is a zip archive that is independently versioned and can be attached to multiple Lambda functions; the layer contents are extracted to /opt in the function's execution environment, allowing shared libraries or utilities to be maintained in one place and updated independently of the functions that use them.
Using a container image for shared code changes the deployment model for all consuming functions and does not provide the same separation-of-concerns benefit as a layer for code that is logically a shared library.
Concept tested: Lambda Layers for sharing reusable code across functions
Source: https://docs.aws.amazon.com/lambda/latest/dg/chapter-layers.html
Community Discussion
No community discussion yet for this question.