Courseiva
Security and Compliance →hardMultiple Choice

DOP-C02 Security and Compliance Practice Question

A company runs a containerized application on Amazon ECS with Fargate. The application needs to access an S3 bucket. The Security team requires that the application never uses long-term credentials and that access is scoped to the specific ECS task. Which approach should be used?

⚠ Common exam trap

Test-takers frequently confuse the IAM role for the EC2 instance (Option C) with the ECS task role, or assume that Secrets Manager (Option B) is acceptable despite it still using long-term credentials, failing to recognize that Fargate tasks require a task-level IAM role for scoped, temporary access.

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

✓

Create an IAM role for the ECS task and reference it in the task definition

ECS tasks using the Fargate launch type can assume an IAM role that is specified in the task definition. This IAM role provides temporary credentials via the ECS task metadata endpoint, ensuring that the application never uses long-term credentials and that permissions are scoped precisely to that task. The Security team's requirements are fully met by this approach.

Answer analysis

Option-by-option breakdown

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

  • ✗

    Embed the IAM user credentials in the container image

    Why it's wrong here

    Hardcoding an IAM user's access key ID and secret access key directly into a container image creates long-lived credentials that are exposed to anyone who can pull the image, inspect its layers, or gain access to the running container. These credentials are not automatically rotated and violate the principle of least privilege; they also persist in the image registry as plaintext, making this approach fundamentally insecure. The correct pattern on ECS is to grant the task an IAM role and let the SDK obtain temporary credentials automatically.

  • ✗

    Store AWS access keys in AWS Secrets Manager and retrieve them at runtime

    Why it's wrong here

    While storing access keys in AWS Secrets Manager removes them from the image, the application still has to load a long-term IAM user key pair at runtime, and it must already have some valid credentials just to call Secrets Manager—creating a bootstrap problem. Additionally, these keys remain valid indefinitely, so a compromise or leak cannot rely on short-lived session rotation. Secrets Manager is meant for confidential data such as database passwords or third-party API tokens, not for distributing IAM credentials; for AWS API access, the ECS task should assume an IAM role instead.

  • ✗

    Use an IAM role for the EC2 instance if using EC2 launch type

    Why it's wrong here

    Using the EC2 instance's IAM role, rather than a task-specific role, only works with the EC2 launch type and cannot be applied to AWS Fargate, where no underlying EC2 instance exists. Even on EC2, the instance role is shared by every task running on that instance, and it is intended for the ECS container agent and ECS operations, not for granting scoped permissions to a particular containerized application. Giving each task its own IAM role in the task definition provides fine-grained control, isolates permissions per workflow, and works consistently across both launch types.

  • ✓

    Create an IAM role for the ECS task and reference it in the task definition

    Why this is correct

    Create an IAM role that defines the exact AWS API permissions the container needs, then specify that role in the task definition using the taskRoleArn parameter. The ECS agent—on Fargate or EC2—assumes this role on behalf of the task and exposes temporary credentials to the container via the ECS credential endpoint, so the SDK automatically rotates them. This is the recommended pattern because it scopes credentials to a single task, follows least privilege, and eliminates the need to manage any static access keys.

Quick reference

AWS S3 Storage Class Comparison

Storage ClassMin DurationRetrievalUse Case
S3 StandardNoneImmediateFrequently accessed data
S3 Standard-IA30 daysImmediateInfrequent access, rapid retrieval
S3 One Zone-IA30 daysImmediateNon-critical infrequent data
S3 Intelligent-TieringNoneImmediate–hoursUnknown or changing access patterns
S3 Glacier Instant90 daysMillisecondsArchive with instant retrieval
S3 Glacier Flexible90 daysMinutes–hoursArchive, flexible retrieval
S3 Glacier Deep Archive180 daysHoursLong-term compliance archive

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 by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

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.