Question 1,192 of 1,740
Security and CompliancemediumMultiple ChoiceObjective-mapped

Quick Answer

The correct answer is to attach an IAM role to the EC2 instance with an S3 access policy. This works because the EC2 instance retrieves temporary, rotating security credentials from AWS Security Token Service (STS) through the instance metadata service (IMDS), eliminating the need to store any long-term access keys on the instance. On the AWS Certified DevOps Engineer Professional DOP-C02 exam, this scenario tests your understanding of the least privilege principle combined with secure credential management—a core DevOps pattern for automating infrastructure without hardcoded secrets. A common trap is selecting an option that stores IAM user keys on the instance or uses an S3 bucket policy with a principal that doesn't account for instance roles. Remember the mnemonic: **R.I.P.** — Role, Instance Metadata, and Proxy (STS) — to recall that the role provides temporary credentials via IMDS, not stored keys.

DOP-C02 Security and Compliance Practice Question

This DOP-C02 practice question tests your understanding of security and compliance. Match the stated requirement to the specific cloud service, access model, or configuration option — many options are valid in isolation but not for this scenario. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.

A DevOps engineer needs to ensure that EC2 instances can access an S3 bucket without storing AWS credentials on the instances. Which solution meets this requirement?

Question 1mediummultiple choice
Full question →

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 an S3 access policy.

Option D is correct because attaching an IAM role to an EC2 instance allows the instance to obtain temporary security credentials from the AWS STS service via the instance metadata service (IMDS). The EC2 instance can then use these credentials to access the S3 bucket without any long-term AWS credentials being stored on the instance. This is the AWS-recommended best practice for granting permissions to AWS services running on EC2.

Key principle: Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

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 an S3 bucket policy that grants access to the EC2 instance's public IP.

    Why it's wrong here

    Bucket policies cannot grant access based on EC2 instance IP alone; they require IAM roles.

  • Store access keys in the EC2 user data script.

    Why it's wrong here

    Storing keys in user data exposes credentials and is not secure.

  • Create an IAM user and embed credentials in the application code.

    Why it's wrong here

    Embedding credentials in code is a security risk and not a best practice.

  • Attach an IAM role to the EC2 instance with an S3 access policy.

    Why this is correct

    The IAM role provides temporary credentials via the instance metadata service.

    Related concept

    Read the scenario before looking for a memorised answer.

Common exam traps

Common exam trap: answer the scenario, not the keyword

The trap here is that candidates may think storing credentials in user data or application code is acceptable, but the DOP-C02 exam specifically tests the principle of using IAM roles to avoid long-term credential storage on EC2 instances.

Detailed technical explanation

How to think about this question

When an IAM role is attached to an EC2 instance, the instance retrieves temporary security credentials from the EC2 instance metadata service (IMDSv2 is recommended for enhanced security) at http://169.254.169.254/latest/meta-data/iam/security-credentials/. These credentials are automatically rotated by AWS STS and have a configurable duration (default 1 hour, max 6 hours). The AWS SDKs and CLI automatically handle credential refresh by polling the metadata service, so applications can seamlessly use S3 without any hardcoded keys.

KKey Concepts to Remember

  • Read the scenario before looking for a memorised answer.
  • Find the constraint that changes the correct option.
  • Eliminate answers that are true in general but not in this case.

TExam Day Tips

  • Watch for words such as best, first, most likely and least administrative effort.
  • Review why wrong options are wrong, not only why the correct option is correct.

Key takeaway

Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Real-world example

How this comes up in practice

A media company stores terabytes of video archives that are accessed once a year for audit purposes. Moving these objects to a cold storage tier (Azure Archive, S3 Glacier, or Google Nearline) costs a fraction of hot storage. Questions like this test whether you understand storage tiers, access frequency tradeoffs, and retrieval latency requirements.

What to study next

Got this wrong? Here's your next step.

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

Related practice questions

Related DOP-C02 practice-question pages

Use these pages to review the topic behind this question. This is how one missed question becomes focused revision.

Practice this exam

Start a free DOP-C02 practice session

Short sessions build daily habit. Longer sessions build exam-day stamina. Try a timed session to simulate real conditions.

FAQ

Questions learners often ask

What does this DOP-C02 question test?

Security and Compliance — This question tests Security and Compliance — Read the scenario before looking for a memorised answer..

What is the correct answer to this question?

The correct answer is: Attach an IAM role to the EC2 instance with an S3 access policy. — Option D is correct because attaching an IAM role to an EC2 instance allows the instance to obtain temporary security credentials from the AWS STS service via the instance metadata service (IMDS). The EC2 instance can then use these credentials to access the S3 bucket without any long-term AWS credentials being stored on the instance. This is the AWS-recommended best practice for granting permissions to AWS services running on EC2.

What should I do if I get this DOP-C02 question wrong?

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

What is the key concept behind this question?

Read the scenario before looking for a memorised answer.

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

2 more ways this is tested on DOP-C02

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. An application running on EC2 needs to access an S3 bucket. To follow the principle of least privilege, what is the recommended approach?

easy
  • A.Store AWS access keys in the application configuration
  • B.Create an IAM role with a policy allowing only necessary S3 actions and attach it to the EC2 instance
  • C.Use an S3 bucket policy to allow access from the EC2 instance's public IP
  • D.Configure the EC2 security group to allow outbound access to S3

Why B: The best practice is to create an IAM role with a policy that grants only the required S3 actions and attach the role to the EC2 instance. This avoids using long-term credentials. Access keys are long-term and insecure. Bucket policy can be used but is not the most secure for instance access. Security group is for network access, not API access.

Variation 2. A company uses AWS CodeBuild for CI/CD. The build project needs to access a private S3 bucket to download artifacts. What is the MOST secure way to grant access?

easy
  • A.Embed the access keys in the buildspec.yml file.
  • B.Create an IAM role with read access to the bucket and attach it to the CodeBuild project.
  • C.Use an S3 bucket policy that grants public read access.
  • D.Store AWS access keys in CodeBuild environment variables.

Why B: Using an IAM role with a trust policy for CodeBuild is the most secure method because it avoids long-term credentials. Option B is correct. Option A is wrong because storing access keys in environment variables is less secure. Option C is wrong because embedding keys in the buildspec file is insecure. Option D is wrong because bucket policies can be used but require the principal to be an IAM user/role; still, the build project should use a role.

Last reviewed: Jun 24, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

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.