AWS Certified Developer – Associate / Question #761 of 557

Question #761

A developer is using AWS SAM to manage a serverless application. After testing in a development environment, the developer needs to deploy the application to production and staging environments. The developer wants to manage environment-specific configurations with minimal additional setup.

Which approach allows the developer to deploy to multiple environments with the LEAST administrative overhead?

A

Create a SAM configuration file in YAML format with separate sections for each environment. Use the SAM deploy command with the --config-env parameter to specify the target environment.

B

Write separate AWS SAM templates for production and staging. Use a deployment script that references the appropriate template with the --template-file option.

C

Modify the existing SAM template to include conditional statements that check the environment type. Use the --parameter-overrides flag to pass the environment during deployment.

D

Use the same SAM template for all environments. Configure environment variables in AWS Lambda functions to handle differences between staging and production.

Explanation

Answer A is correct because AWS SAM supports environment-specific configurations via a single samconfig.toml file. By defining separate sections (e.g., [staging], [production]) in this file, the developer can store environment-specific parameters (e.g., ARNs, bucket names) and deploy using sam deploy --config-env [env]. This approach avoids maintaining multiple templates (Option B), reduces manual parameter overrides (Option C), and ensures infrastructure differences (not just Lambda variables) are managed (unlike Option D). SAM's built-in configuration management simplifies deployments across environments with minimal overhead.

Key Points:
- SAM's samconfig.toml centralizes environment configurations.
- --config-env selects the environment's parameters during deployment.
- Avoids code duplication (Option B) and manual errors (Option C/D).
- Environment variables (Option D) cannot manage non-Lambda resources (e.g., DynamoDB tables).

Answer

The correct answer is: A