考题解析 | 使用 IAM 角色为 EC2 添加权限


  题目

A company is implementing a new business application. The application runs on two Amazon EC2 instances and uses an Amazon S3 bucket for document storage. A solutions architect needs to ensure that the EC2 instances can access the S3 bucket.
What should the solutions architect do to meet this requirement?
A. Create an IAM role that grants access to the S3 bucket. Attach the role to the EC2 instances.
B. Create an IAM policy that grants access to the S3 bucket. Attach the policy to the EC2 instances.
C. Create an IAM group that grants access to the S3 bucket. Attach the group to the EC2 instances.
D. Create an IAM user that grants access to the S3 bucket. Attach the user account to the EC2 instances.

  参考答案

A

  参考解析

技巧:排除明显错误选项,在没有明显错误的选项中选择最合理的选项。
某公司正在实施一个新的业务应用程序,该应用程序运行在两个Amazon EC2实例上,并使用Amazon S3存储桶来存储文档。解决方案架构师需要确保EC2实例能够访问S3存储桶。

A. 正确。创建一个授予访问 S3 存储桶权限的 IAM 角色。将该角色附加到 EC2 实例上。IAM 角色是一种可以附加到 AWS 资源(如 EC2 实例)的权限集合。通过为 EC2 实例附加一个具有 S3 存储桶访问权限的 IAM 角色,实例就可以使用该角色来访问 S3 存储桶。这种方法既安全又方便,因为不需要在实例上存储访问密钥。
B. 不正确。创建一个授予访问 S3 存储桶权限的 IAM 策略。将该策略附加到 EC2 实例上。IAM 策略本身不能直接附加到 EC2 实例上。策略需要被附加到用户、角色或组上。对于 EC2 实例,通常是通过附加具有所需权限的角色来实现的。
C. 不正确。创建一个授予访问 S3 存储桶权限的 IAM 组。将该组附加到 EC2 实例上。IAM 组是用于管理具有相同权限的多个用户的集合。组本身不能直接附加到 EC2 实例上。
D. 不正确。创建一个授予访问 S3 存储桶权限的 IAM 用户。将该用户帐户附加到 EC2 实例上。IAM 用户是用于表示个体身份(如人类或应用程序)的实体,并且通常与访问密钥相关联。将 IAM 用户附加到 EC2 实例上并不是一种安全的做法,因为这意味着需要在实例上存储访问密钥,这可能会增加安全风险。

  官方参考文档

IAM 角色
IAM 用户
IAM 用户组