Courseiva

DVA-C02 Ref function Practice Question

A developer is deploying a serverless application using AWS SAM. The application includes an API Gateway endpoint that invokes a Lambda function. The developer wants to pass a stage name as a parameter to the Lambda function. How should the developer define the Lambda function's environment variable in the SAM template?

⚠ Common exam trap

DVA-C02 often tests the correct use of intrinsic functions, and candidates may confuse Ref with Fn::GetAtt or Fn::ImportValue, or attempt to reference outputs incorrectly.

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

✓

Use the parameter reference 'Ref: StageName' in the environment variable mapping.

The developer should use the parameter reference 'Ref: StageName' in the environment variable mapping. In AWS SAM, you can reference parameters defined in the template using the Ref intrinsic function. This allows the stage name to be passed as an environment variable to the Lambda function.

Answer analysis

Option-by-option breakdown

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

  • ✓

    Use the parameter reference 'Ref: StageName' in the environment variable mapping.

    Why this is correct

    This is the correct approach for dynamically injecting a value provided at deployment time into a Lambda function's environment variables. `Ref` is a CloudFormation intrinsic function that retrieves the value of a top-level parameter declared in the `Parameters` section of the template. By defining `StageName` as a parameter and referencing it with `Ref: StageName` in the Lambda's environment variable configuration, the developer ensures the stage name (e.g., 'dev', 'prod') is passed during stack creation or update, making the application adaptable across different environments without code changes.

  • ✗

    Define the environment variable as 'Stage: dev' in the Lambda function configuration.

    Why it's wrong here

    Hardcoding the environment variable `Stage` to a static value like 'dev' directly within the Lambda function configuration prevents the application from being easily deployed to multiple environments (e.g., 'test', 'prod') without modifying the CloudFormation template itself. This approach lacks flexibility and violates the principle of separating configuration from code, making it cumbersome to manage different deployment stages. It would require manual updates for each environment, increasing the risk of errors and reducing automation capabilities.

  • ✗

    Use 'Fn::GetAtt: [AWS::StackName, Outputs.StageName]' to get the stage name.

    Why it's wrong here

    The `Fn::GetAtt` intrinsic function is used to retrieve an attribute from a resource in the *current* stack, not to reference a parameter or an output from *another* stack. While `AWS::StackName` is a pseudo-parameter, `Outputs.StageName` would imply an output from a resource *within* the `AWS::StackName` resource, which is incorrect syntax and usage. `Fn::GetAtt` is typically used with `[LogicalResourceId, AttributeName]`, and `StageName` is intended as a template parameter, not an attribute of `AWS::StackName` or an output of a resource in this context.

  • ✗

    Use 'Fn::ImportValue: StageName' to import from another stack.

    Why it's wrong here

    `Fn::ImportValue` is specifically designed for sharing output values between *different* CloudFormation stacks within the same AWS account and region. It allows a stack to consume a value that was explicitly exported by another stack using `Fn::Export`. In this scenario, the question implies `StageName` is a parameter for the *current* stack being deployed, not an output from a separate, pre-existing stack that needs to be imported. Therefore, using `Fn::ImportValue` is inappropriate for referencing a parameter defined within the same template.

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

Courseiva writes every DVA-C02 question from scratch — 1,135 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written and reviewed by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

Last reviewed September 2026 · checked against the official Amazon Web Services exam blueprint

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.