SAP-C02 practice question 15 of 35

A company is developing a new serverless API by using Amazon API Gateway and AWS Lambd a. The company integrated the Lambda functions with API Gateway to use several shared libraries and custom classes. A solutions architect needs to simplify the deployment of the solution and optimize for code reuse. Which solution will meet these requirements?

Full set: 689 questions

Domain Design for New Solutions

Answer options
A: Deploy the shared libraries and custom classes into a Docker image. Store the image in an S3 bucket. Create a Lambda layer that uses the Docker image as the source. Deploy the API's Lambda functions as Zip packages. Configure the packages to use the Lambda layer.
B: Deploy the shared libraries and custom classes to a Docker image. Upload the image to Amazon Elastic Container Registry (Amazon ECR). Create a Lambda layer that uses the Docker image as the source. Deploy the API's Lambda functions as Zip packages. Configure the packages to use the Lambda layer. Correct answer
C: Deploy the shared libraries and custom classes to a Docker container in Amazon Elastic Container Service (Amazon ECS) by using the AWS Fargate launch type. Deploy the API's Lambda functions as Zip packages. Configure the packages to use the deployed container as a Lambda layer.
D: Deploy the shared libraries, custom classes, and code for the API's Lambda functions to a Docker image. Upload the image to Amazon Elastic Container Registry (Amazon ECR). Configure the API's Lambda functions to use the Docker image as the deployment package.
Correct Answer:
B. Deploy the shared libraries and custom classes to a Docker image. Upload the image to Amazon Elastic Container Registry (Amazon ECR). Create a Lambda layer that uses the Docker image as the source. Deploy the API's Lambda functions as Zip packages. Configure the packages to use the Lambda layer.
Explanation

AWS Lambda layers are the supported mechanism for sharing libraries and custom code across many Lambda functions. For layers whose contents are delivered as a container image, the image must be pushed to Amazon ECR and referenced when the layer is created. Functions that stay in the traditional .zip format can attach that layer and automatically gain access to the shared components, giving one authoritative copy and greatly simplifying deployments.
Option B follows exactly this model: build the shared libraries and classes into a container image, push it to ECR, create a Lambda layer from that image, then attach the layer to every Lambda function that backs the API.

Why Incorrect

A. Lambda layers accept container images only from ECR or zipped archives from S3; an image stored in S3 is not a valid source.
C. A running ECS/Fargate container cannot be attached as a Lambda layer; Lambda layers are static artifacts in ECR or S3.
D. Packaging every function as its own container image duplicates the shared code in each image, defeating the goal of reuse and increasing deployment effort.

References

1. AWS Lambda Developer Guide

“Creating and sharing Lambda layers (container images)”

Section: Layers as container images – requirement to push to Amazon ECR. https://docs.aws.amazon.com/lambda/latest/dg/using-layers.html

2. AWS Lambda Developer Guide

“Lambda deployment packages”

Paragraph: “A function deployment package is a .zip file or a container image stored in ECR.” https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-package.html

3. AWS Lambda Developer Guide PDF (2023-12-07)

p.121-124

“Working with Lambda layers”— describes single copy of shared code

attachment to many functions

and ECR requirement for image layers.

Scroll to Top