Courseiva
Security →mediumMultiple Choice

DVA-C02 Security Practice Question

A developer is deploying an application on Amazon EC2 instances that need to securely retrieve secrets from AWS Secrets Manager. What is the MOST secure way to provide the necessary permissions without hardcoding credentials?

⚠ Common exam trap

Watch out — candidates often think environment variables or S3 configuration files are secure enough, but the exam emphasizes that any form of static credential storage (including environment variables) is insecure compared to IAM roles, which provide automatic, temporary, and rotated credentials.

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

✓

Attach an IAM role to the EC2 instance with permission to access Secrets Manager.

Attaching an IAM role to the EC2 instance is the most secure method because it leverages temporary security credentials obtained via the EC2 instance metadata service (IMDS). This eliminates the need to hardcode, embed, or store any long-term credentials on the instance, adhering to the AWS Well-Architected Framework's security pillar. The IAM role's policy grants the instance precise permissions to call Secrets Manager APIs like GetSecretValue, ensuring least privilege.

Answer analysis

Option-by-option breakdown

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

  • ✗

    Store the secret in an environment variable.

    Why it's wrong here

    Environment variables expose the secret in process listings, container metadata and crash dumps, and grant no rotation or audit trail. It is tempting because it avoids code changes and is common for non-sensitive settings, and would be correct for ordinary configuration values rather than retrievable secrets.

  • ✓

    Attach an IAM role to the EC2 instance with permission to access Secrets Manager.

    Why this is correct

    An IAM role attached to the EC2 instance delivers temporary, automatically rotated credentials through the instance metadata service, so no long-term secrets are stored on the instance. This satisfies the no-hardcoded-credentials constraint while granting least-privilege access to Secrets Manager.

  • ✗

    Embed the secret in the application code.

    Why it's wrong here

    Embedding the secret in application code stores plaintext credentials in source control and deployment artefacts, directly violating the no-hardcoding requirement. It is tempting because it removes runtime lookups, and would be correct only for non-sensitive constants, never for secrets that must be rotated and audited.

  • ✗

    Use a configuration file stored in S3 with bucket policy.

    Why it's wrong here

    A configuration file in S3 still contains the secret in plaintext, and bucket policy grants access to the object rather than authenticating the EC2 instance's identity to Secrets Manager. It is tempting because S3 offers encryption and access control, and would be correct for non-secret configuration data.

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 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.