Courseiva
Security and Compliance →mediumMultiple Choice

DOP-C02 Security and Compliance Practice Question

A company is using AWS Secrets Manager to store database credentials for a multi-tier application. The application runs on EC2 instances in an Auto Scaling group. The DevOps engineer has configured the instances to retrieve the secret at boot time using a script that calls the AWS CLI. Recently, the security team discovered that the secret was exposed in the instance's user data logs. The engineer needs to implement a more secure method to access the secret without storing it in user data. The application code can be modified. The environment uses IAM roles for EC2. Which solution best meets the security requirements?

⚠ Common exam trap

DOP-C02 often tests the misconception that 'encrypting' a secret in user data makes it safe — candidates forget that user data is readable via the EC2 API and IMDS, so ciphertext plus accessible decryption is still a leak.

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

✓

Modify the application code to use the AWS SDK to retrieve the secret from Secrets Manager using the instance's IAM role.

The most secure and operationally sound approach is to have the application retrieve the secret at runtime using the AWS SDK, authenticating via the EC2 instance profile (IAM role). This eliminates any need to embed the secret in user data, config files, or environment variables, and it leverages Secrets Manager's native rotation, versioning, and audit trail. Because the environment already uses IAM roles for EC2, no additional credential management is required.

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 a configuration file on the EC2 instance and encrypt the file system.

    Why it's wrong here

    Persisting the secret in a configuration file on an EC2 instance—even with an encrypted file system—does not protect it from any process with local access to the running instance. The OS must hold the decryption key (e.g., a KMS-backed EBS key) available to the kernel, so an attacker with compromised credentials or an exploited application can simply read the file while the instance is running. Additionally, this approach lacks audit logging, secret rotation, and any fine-grained permission control, and the secret will be copied into any AMI or snapshot created from the instance.

  • ✗

    Store the secret in AWS Systems Manager Parameter Store and retrieve it via the AWS CLI at boot time.

    Why it's wrong here

    Retrieving the secret from Parameter Store via the AWS CLI at boot time only moves the problem into shell history and user data. The CLI command that fetches the secret must be embedded in user data, which is visible via the instance metadata service and the EC2 console, so anyone with read access to that metadata or the launch template can see the command and potentially intercept the returned secret. While Parameter Store can hold secrets, it does not natively provide the same rotation or access-tracking features as Secrets Manager, and the instance role would need broadly scoped permissions that raise the blast radius if compromised.

  • ✓

    Modify the application code to use the AWS SDK to retrieve the secret from Secrets Manager using the instance's IAM role.

    Why this is correct

    Using the AWS SDK inside the application to retrieve the secret from Secrets Manager is the correct pattern because the secret is fetched at runtime, encrypted in transit, and never written to user data, environment variables, or disk. The EC2 instance profile's IAM role gives the SDK temporary, automatically rotated credentials, so no hard-coded access keys or CLI scripts are required. This approach leverages Secrets Manager's built-in rotation, CloudTrail auditing, and fine-grained IAM policies that can limit which secrets a given instance role can read, and it lets the SDK cache the secret to minimize latency while still respecting rotation.

  • ✗

    Use a KMS key to encrypt the secret and store the encrypted value in user data.

    Why it's wrong here

    Encrypting the secret with a KMS key and placing the ciphertext in user data is flawed because user data is an unencrypted part of instance metadata that any process with access to the metadata service (or an administrator reviewing the EC2 console/CloudTrail) can retrieve. The KMS key does not protect the secret at rest; instead, the IAM role attached to the instance almost certainly has permission to call KMS Decrypt so the application can use the secret, meaning an attacker who gains access to the ciphertext from user data can simply decrypt it by invoking KMS with that instance's role. Because the ciphertext is static, rotating the underlying secret would require editing the user data and relaunching the instance, creating operational overhead and leaving historical copies in metadata snapshots.

About these practice questions

One of 1,298 original DOP-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 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 DOP-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 DOP-C02 exam.