如何创建动态 AWS 环境和拆解?

How to create a dynamic AWS environment and teardown?

我知道这听起来像是一个基本问题,但我还不知道该怎么做。

我们正在努力建立一个测试环境来筛选云工程师和大数据面试的候选人。

我们正在研究可能使用 Cloudformation 服务创建按需 AWS 环境,并测试用户是否能够在环境中执行特定任务,例如使用 boto3 创建 s3 存储桶、分配角色、创建安全组等。

但是一旦筛选完成,我们希望自动拆除之前创建的整个设置。

可能有多位考生同时参加考试。我们想要创建环境(可能包含其他用户不可见的 ec2 实例、s3 存储桶等)并在测试完成后拆除它们。

我们考虑过使用 IAM 角色为每个候选人动态创建 IAM 用户,并自动创建堆栈并在测试完成后删除这些用户。

但是,我认为用户将能够看到其他用户创建的资源,这不是我们所期望的。

是否有任何其他更好的方法可用于创建这些环境或实验室并为用户删除它们?像 ITversity 和 Qwiklabs 这样的东西。

登录用户应该有权访问和查看仅为他创建的资源。

求推荐。

查询 1: 假设我已经创建了 10 IAM roles 个使用和一个用户使用这些角色中的每一个。从 IAM role 1 创建的用户是否能够看到 VPCsEC2 instancesS3 或由 IAM role 2 创建的另一个用户创建的任何其他资源?

资源会完全从一个IAM role隔离到另一个吗?

或者像 AWS Organizations 这样的服务在这种情况下会有很大帮助吗?

However, I think the users will be able to see the resources created by other users which is not what we are expecting.

AWS 资源对其所有者以及与所有者共享资源的人可见。
新 IAM 用户根本看不到任何 AWS 资源。

我建议查看以下 AWS 文档中的场景 3

在 AWS 云中设置多用户环境 (用于课堂培训和研究)

它引用了 "students" 环境,但是它应该满足面试候选人的测试需求。

The “Separate AWS Account for Each User” scenario with optional consolidated billing provides an excellent environment for users who need a completely separate account environment, such as researchers or graduate students. It is similar to the “Limited User Access to AWS Management Console” scenario, except that each IAM user is created in a separate AWS account, eliminating the risk of users affecting each other’s services. As an example, consider a research lab with 10 graduate students. The administrator creates one paying AWS account, 10 linked student AWS accounts, and 1 restricted IAM user per linked account. The administrator provisions separate AWS accounts for each user and links the accounts to the paying AWS account. Within each account, the administrator creates an IAM user and applies access control policies. Users receive access to an IAM user within their AWS account. They can log into the AWS Management Console to launch and access different AWS services, subject to the access control policy applied to their account. Students don’t see resources provisioned by other students. One key advantage of this scenario is the ability for a student to continue using the account after the completion of the course. For example, if students use AWS resources as part of a startup course, they can continue to use what they have built on AWS after the semester is over.

https://d1.awsstatic.com/whitepapers/aws-setting-up-multiuser-environments-education.pdf

Qwiklabs 环境的工作原理如下:

  • 维护 AWS 账户池
  • 当学生开始实验时,这些帐户之一会分配给 lab/student
  • 启动 CloudFormation 模板以配置初始资源
  • 学生登录(通过 IAM 用户或联合登录)已配置并分配了一组有限的权限
  • 在实验结束时,学生登录被删除,"reaper" 删除帐户中的资源并删除 CloudFormation 堆栈

"reaper" 是一系列脚本,它们递归地遍历每个区域中的每个服务并删除在实验室期间创建的资源。可以使用 rebuy-de/aws-nuke: Nuke a whole AWS account and delete all its resources.

获得类似的功能

您可以尝试自己创建这样的环境。