DVA-C02 · Question #273
A developer is creating an application that reads and writes to multiple Amazon S3 buckets. The application will be deployed to an Amazon EC2 instance. The developer wants to make secure API…
The correct answer is B. Associate the EC2 instance with an IAM role that has an IAM policy that allows s3:ListBucket and. IAM instance profiles allow EC2 instances to assume an IAM role with specific permissions, enabling secure, credential-free API calls to AWS services while applying least privilege by granting only the required S3 actions.
Question
A developer is creating an application that reads and writes to multiple Amazon S3 buckets. The application will be deployed to an Amazon EC2 instance. The developer wants to make secure API requests from the EC2 instances without the need to manage the security credentials for the application. The developer needs to apply the principle of least privilege. Which solution will meet these requirements?
Options
- ACreate an IAM user. Create access keys and secret keys for the user. Associate the user with an
- BAssociate the EC2 instance with an IAM role that has an IAM policy that allows s3:ListBucket and
- CAssociate the EC2 instance with an IAM role that has an AmazonS3FullAccess AWS managed
- DCreate a bucket policy on the S3 bucket that allows s3:ListBucket and s3:*Object permissions to
How the community answered
(35 responses)- A6% (2)
- B80% (28)
- C3% (1)
- D11% (4)
Why each option
IAM instance profiles allow EC2 instances to assume an IAM role with specific permissions, enabling secure, credential-free API calls to AWS services while applying least privilege by granting only the required S3 actions.
Creating an IAM user with access keys and secret keys requires embedding or managing long-lived credentials in the application or environment, which increases security risk and contradicts the requirement to avoid managing credentials.
Attaching an IAM role with an IAM policy granting only `s3:ListBucket` and `s3:*Object` to the EC2 instance provides the minimum permissions needed for read/write operations on S3 buckets. The instance automatically obtains temporary credentials via the instance metadata service, eliminating the need to manage long-lived access keys.
The `AmazonS3FullAccess` managed policy grants all S3 actions including bucket deletion, policy changes, and replication configuration, which violates the principle of least privilege for an application that only needs read and write access.
A bucket policy can restrict which principals access a bucket, but it cannot grant the EC2 instance the ability to authenticate to AWS without credentials; a bucket policy alone does not provide a mechanism for credential-free API calls from EC2.
Concept tested: IAM instance profiles and least privilege for EC2 to S3 access
Source: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_switch-role-ec2_instance-profiles.html
Community Discussion
No community discussion yet for this question.