Courseiva
DeploymenthardMultiple ChoiceObjective-mapped

DVA-C02 Deployment Practice Question

A developer is deploying a serverless application using AWS SAM. The application consists of multiple Lambda functions and an API Gateway REST API. The developer needs to ensure that the API Gateway endpoint is created before the Lambda functions are deployed, because the functions need the endpoint URL as an environment variable. How should the developer configure the SAM template?

⚠ Common exam trap

It's easy for candidates to think `DependsOn` is sufficient to pass the endpoint URL, but it only orders creation and does not inject the URL into environment variables, which requires an intrinsic function reference like `Fn::Sub` or `Fn::GetAtt`.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

Define the Lambda functions to use the ServerlessRestApi implicit API and reference the API's output in the function's environment variables

AWS SAM automatically creates an implicit API Gateway REST API (logical ID `ServerlessRestApi`) when you define an `AWS::Serverless::Api` or use the `Events` property on a function. You can reference its endpoint URL using the `Fn::Sub` intrinsic function with the `ServerlessRestApi` logical ID, such as `!Sub 'https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/${Stage}'`. This ensures the API Gateway resource is created before the Lambda functions that reference it, as CloudFormation resolves dependencies through intrinsic function references.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Separate the deployment into two stacks: first deploy API Gateway, then deploy Lambda functions

    Why it's wrong here

    Separating the deployment into two distinct CloudFormation stacks introduces unnecessary operational overhead and complexity for a tightly coupled serverless application. While technically feasible using cross-stack references, AWS Serverless Application Model (SAM) is specifically designed to manage API Gateway and Lambda functions within a single, cohesive stack. This approach negates the benefits of SAM's simplified deployment model and automatic dependency resolution, making deployments more cumbersome.

  • Add a DependsOn clause to each Lambda function resource to wait for the API Gateway resource

    Why it's wrong here

    Adding a DependsOn clause to each Lambda function resource is superfluous when using CloudFormation's native capabilities for intrinsic dependency resolution. When a Lambda function resource logically references an API Gateway resource, such as through the `Events` property in SAM, CloudFormation automatically infers and establishes the correct deployment order. Explicitly defining `DependsOn` in this scenario adds verbose, redundant configuration without providing additional benefit or preventing deployment issues.

  • Define the Lambda functions to use the ServerlessRestApi implicit API and reference the API's output in the function's environment variables

    Why this is correct

    Defining Lambda functions to use the `ServerlessRestApi` implicit API within the AWS Serverless Application Model (SAM) template is the recommended and most efficient approach. SAM automatically provisions and configures the API Gateway and integrates it with the Lambda functions, establishing all necessary permissions and dependencies. Referencing the API's output, such as its endpoint URL, in the function's environment variables provides a clean and dynamic way for the Lambda function to interact with its associated API at runtime, ensuring correct configuration.

  • Use a custom resource in CloudFormation to create the API Gateway endpoint before Lambda functions

    Why it's wrong here

    Utilizing a custom resource in CloudFormation to create the API Gateway endpoint before Lambda functions is an overly complex and unnecessary solution for this common deployment pattern. Custom resources are typically reserved for provisioning resources not natively supported by CloudFormation, which is not the case for API Gateway. This approach introduces additional Lambda function code, execution overhead, and maintenance burden, when native SAM constructs handle this seamlessly and more efficiently.

Visual reference

Client Recursive Resolver Root DNS (13 root servers) TLD DNS (.com, .org, …) Authoritative example.com query IP addr answer

Quick reference

Cloud Service Model Comparison

ModelYou ManageProvider ManagesExamples
IaaSOS, runtime, apps, dataHardware, hypervisor, networkingEC2, Azure VMs, GCP Compute Engine
PaaSApps and dataOS, runtime, middleware, hardwareElastic Beanstalk, Azure App Service
SaaSData and settings onlyEverything elseMicrosoft 365, Salesforce, Workday
FaaS / ServerlessFunction code onlyInfra, scaling, runtimeLambda, Azure Functions, Cloud Run
CaaSContainers and appsKubernetes, OS, hardwareEKS, AKS, GKE

About these practice questions

One of 724 original DVA-C02 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This DVA-C02 practice question is part of Courseiva's free Amazon Web Services certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the DVA-C02 exam.