Jeff’s Note #
Unlike generic exam dumps, ADH analyzes this scenario through the lens of a Real-World Lead Developer.
For DVA-C02 candidates, the confusion often lies in how to manage AWS credentials securely for applications running on EC2. In production, this is about knowing exactly why IAM Roles attached to EC2 beat embedding long-lived credentials in your app. Let’s drill down.
The Certification Drill (Simulated Question) #
Scenario #
A software engineering team at DataStream Solutions is building an internal analytics app hosted on an Amazon EC2 instance. The app must programmatically upload sensitive reports as files to a company-owned Amazon S3 bucket. The team wants to implement the most secure and AWS-recommended way to enable this file transfer without embedding sensitive credentials in the application.
The Requirement: #
Securely allow the EC2-hosted application to transfer files to a specific Amazon S3 bucket while following AWS security best practices for credential management.
The Options #
- A) Create a dedicated IAM user, generate an access key and secret key for this user, and store these credentials in the application’s environment variables on the EC2 instance.
- B) Create an IAM role with an access key, store the access key in environment variables, and assign the IAM role to the EC2 instance.
- C) Create an IAM role with permissions limited to only the required S3 API actions and attach this IAM role directly to the EC2 instance profile.
- D) Configure the S3 bucket policy to allow access based on the EC2 instance ID, enabling the application to upload files without additional IAM credentials.
Google adsense #
leave a comment:
Correct Answer #
C
Quick Insight: The Developer Credential Management Imperative #
- When running applications on EC2, IAM Roles attached to instance profiles provide short-term, automatically rotated credentials that eliminate risks of leaking static access keys.
- Embedding access keys in environment variables (Option A/B) is insecure and violates AWS best practices.
- S3 bucket policies cannot directly authenticate EC2 instance IDs (Option D), only IAM principals or specific conditions.
Content Locked: The Expert Analysis #
You’ve identified the answer. But do you know the implementation details that separate a Junior from a Senior?
The Expert’s Analysis #
Correct Answer #
Option C
The Winning Logic #
Attaching an IAM role with S3 permissions to the EC2 instance’s instance profile leverages AWS’s secure credential management system called “Instance Metadata Service” (IMDS). The application uses SDK calls that automatically retrieve temporary credentials with limited scope and auto-rotate, significantly reducing risk from credential leakage.
- The IAM role can be scoped to least privilege — granting only necessary S3 actions (e.g.,
s3:PutObjectfor the target bucket). - The application code remains free from hardcoded credentials, enabling safer codebases and easier credential rotation.
The Trap (Distractor Analysis): #
-
Why not A?
Embedding long-lived IAM user credentials in environment variables exposes your app if an attacker gains instance access. These credentials don’t rotate automatically, leading to risk and operational overhead. -
Why not B?
IAM roles do not have access keys. Creating an access key for a role is impossible. This option is technically incorrect. -
Why not D?
S3 bucket policies do not accept EC2 instance IDs as principals or conditions. Access control is based on IAM identities (roles/users) or other S3-specific conditions, not instance IDs.
The Technical Blueprint #
Developer CLI & IAM JSON Policy Snippet for Option C #
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:PutObject"
],
"Resource": "arn:aws:s3:::datastream-analytics-bucket/*"
}
]
}
Attach this policy to an IAM role, then associate the role with the EC2 instance profile:
aws iam create-role --role-name AnalyticsAppS3Role --assume-role-policy-document file://trust-policy.json
aws iam put-role-policy --role-name AnalyticsAppS3Role --policy-name S3UploadPolicy --policy-document file://s3-upload-policy.json
aws ec2 associate-iam-instance-profile --instance-id i-0123456789abcdef0 --iam-instance-profile Name=AnalyticsAppS3Role
The Comparative Analysis #
| Option | API Complexity | Security Risk Level | Use Case |
|---|---|---|---|
| A | Low | High (Static Keys) | Legacy, not recommended |
| B | Invalid (No role keys) | N/A | Misunderstands IAM role function |
| C | Simple | Low (Temporary creds) | Best Practice for EC2 app S3 access |
| D | N/A | No direct effect | Incorrect assumption about instance IDs |
Real-World Application (Practitioner Insight) #
Exam Rule #
For the exam, always pick IAM Roles attached to EC2 instance profiles when you see an application running on EC2 accessing other AWS services.
Real World #
In production, embedding static keys is a critical security anti-pattern. Using instance roles simplifies credential management, improves security posture, and aligns with AWS’s “least privilege” guidance.
(CTA) Stop Guessing, Start Mastering #
Disclaimer
This is a study note based on simulated scenarios for the AWS DVA-C02 exam.