Courseiva
Security and Compliance →easyMultiple Choice

DOP-C02 Security and Compliance Practice Question

A developer needs to allow an EC2 instance to read from an S3 bucket. Which is the most secure way to grant this 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 with an S3 read policy and attach it to the EC2 instance profile.

The most secure way to grant an EC2 instance access to an S3 bucket is to use an IAM role with an S3 read policy attached to the instance profile. This allows the instance to obtain temporary security credentials via the instance metadata service, avoiding hardcoded keys or exposing credentials. Option A is wrong because root credentials are overly privileged and should never be used for routine access. Option B is wrong because storing access keys in user data is insecure—keys can be exposed through instance metadata or logs. Option C is wrong because bucket policies based on public IP addresses are not secure; IPs can change and other instances could have the same IP, plus S3 bucket policies should not rely on IP addresses for authentication. Option D is the correct approach because it uses IAM roles, the best practice for granting permissions to AWS services.

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 root user credentials of the AWS account.

    Why it's wrong here

    The root user of the AWS account possesses full, unrestricted administrative access to all resources and billing. Using these credentials for an EC2 application violates the fundamental principle of least privilege, exposes the account to catastrophic compromise if the keys are ever leaked, and provides no way to scope permissions down to a single S3 read requirement. Best practice is to delegate permissions through an IAM role with a narrowly defined policy.

  • ✗

    Store AWS access keys in the instance's user data and use them in the application.

    Why it's wrong here

    Embedding long-term AWS access keys in instance user data is insecure because user data is readable by any process or user with access to the local metadata service (169.254.169.254/latest/user-data) and is also visible in the EC2 console. These static credentials never expire and will continue to work even if the instance is terminated, creating a persistent exposure risk. An instance profile instead injects short-lived, automatically rotated credentials.

  • ✗

    Create an S3 bucket policy that allows the EC2 instance's public IP address.

    Why it's wrong here

    An S3 bucket policy cannot authorize an EC2 instance directly; to restrict by IP you would need a condition key like aws:SourceIp, but that only checks the source IP address of the request, not the identity of the instance, so any client on that IP (e.g., behind a NAT) would inherit the permission. EC2 public IPs are also dynamic by default and can change after stop/start, making the policy fragile. The correct approach is to grant identity-based permissions via an IAM role attached to the instance profile, not resource-based bucket policy conditions.

  • ✓

    Create an IAM role with an S3 read policy and attach it to the EC2 instance profile.

    Why this is correct

    Create an IAM role with a policy such as s3:GetObject and s3:ListBucket, then attach it to the EC2 instance profile. The instance will automatically obtain temporary security credentials from AWS STS through the instance metadata service, which are rotated every few hours and never stored on disk. This follows least privilege, avoids long-lived keys, and is the AWS best practice for granting permissions to a running instance.

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.