Question

Difficulty: MediumServerless Development with AWS Lambda

A developer is building a serverless application consisting of multiple AWS Lambda functions written in Python. Each function needs to use the same large, third-party utility library as well as a shared custom logging module. The developer wants to optimize the deployment process by minimizing the deployment package size of the individual Lambda functions and centralizing the management of these shared dependencies. Which approach should the developer use to meet these requirements with the least operational overhead?

  1. Package the shared utility library and the logging module into an AWS Lambda layer, upload the layer, and configure each Lambda function to reference this layer.Answer
  2. B
    Upload the shared libraries to an Amazon S3 bucket, configure the Lambda function's IAM trust policy to grant read access to the S3 bucket, and download the libraries at runtime.
  3. C
    Write code inside the Lambda handler function to download the library from a public repository into the /tmp directory using pip during each execution.
  4. D
    Deploy the Lambda functions inside a private VPC subnet to access an Amazon Elastic File System (EFS) containing the libraries, without configuring a NAT Gateway or VPC endpoint.

Answer

Package the shared utility library and the logging module into an AWS Lambda layer, upload the layer, and configure each Lambda function to reference this layer.
AWS Lambda layers are designed to isolate and share common dependencies across multiple Lambda functions. This centralizes dependency management, reduces deployment package sizes, and optimizes deployment workflows.

Step-by-Step Solution

1
Identify the requirement to share a common utility library and logging module across multiple functions while reducing deployment package sizes.
Recognized that bundling libraries into every function zip file is redundant and inefficient.
Large libraries significantly increase deployment package size, which slows down deployment times and exceeds the storage limit of functions.
2
Evaluate native AWS Lambda packaging tools.
Determined that AWS Lambda Layers allow separating dependencies from the main application deployment package.
Layers are specifically designed to share code and data across multiple functions, reducing package size and simplifying updates.
3
Select the layer configuration as the optimal approach.
Created a single deployment artifact containing the libraries, published it as a Lambda layer, and configured functions to use it.
This avoids execution runtime overhead and uses identity-based permission roles correctly.

Key Concept

AWS Lambda Layers dependency management
Estimated Time:1m 30s
Rate this question