AWS Certified Solutions Architect - Professional / Question #685 of 529

Question #685

A company is developing a serverless application using Amazon API Gateway and AWS Lambda. The Lambda functions require several common dependencies and shared libraries to be reused across multiple functions.

A solutions architect needs to ensure that the deployment process is simplified and that the common code is efficiently reused.

Which solution meets these requirements?

A

Package the shared libraries into a Docker image and store it in an S3 bucket. Create a Lambda layer from this image. Deploy the Lambda functions as ZIP archives configured to use the layer.

B

Package the shared libraries into a Docker image and upload it to Amazon ECR. Create a Lambda layer referencing this image. Deploy the Lambda functions as ZIP archives configured to use the layer.

C

Deploy the shared libraries in a Docker container using Amazon ECS with AWS Fargate. Configure the Lambda functions to access this container as a layer via VPC networking.

D

Package the shared libraries and Lambda function code into a single Docker image stored in Amazon ECR. Configure each Lambda function to use this image as its deployment package.

Explanation

Option B is correct because AWS Lambda layers are designed to manage shared code and dependencies separately from Lambda functions. By packaging shared libraries into a Docker image stored in Amazon ECR (a service optimized for container images), a Lambda layer can reference these libraries. When Lambda functions are deployed as ZIP archives, they can efficiently reuse the layer, reducing redundancy and simplifying deployment.

Other options are incorrect:
- A: S3 is not the correct service for storing Docker images; ECR is purpose-built for container images.
- C: Using ECS/Fargate adds unnecessary complexity and latency, as Lambda layers are designed for direct code reuse.
- D: Packaging all code into a single Docker image eliminates the benefits of layers, leading to larger deployment packages and inefficient updates.

Key Points:
1. Lambda layers enable code/dependency reuse across functions.
2. ECR is the correct repository for Docker images in AWS.
3. ZIP-based Lambda deployments can leverage layers for shared libraries.

Answer

The correct answer is: B