如何使用python和yaml文件在AWS组织单位下创建子组织单位?

时间:2018-10-23 17:13:38

标签: python python-3.x amazon-web-services aws-sdk boto3

任务:使用python和yaml在aws组织单位(OU)下创建子组织单位

使用下面的代码,我可以在AWS组织中创建多个OU

yaml文件:

 accounts:
  - Organization-Unit: 
     test1
  - Organization-Unit: 
     test2

用于创建OU的Python文件:

     #!/usr/bin/env python
     from __future__ import print_function
     import json
     import boto3
     import yaml
     client = boto3.client('organizations')
     with open("xyz.yaml", 'r') as ymlfile:
       config = yaml.safe_load(ymlfile)
     accounts = config['accounts']

     for account in accounts:
       try:
         response = client.create_organizational_unit(
         ParentId = "",
         Name     = account['Organization-Unit'])
         print(response)         
       except Exception as error:
        print(error)

现在我要在OU下创建子OU,如下所示:

yaml文件:

         accounts:
         - Organization-Unit: 
           test1
             - sub-Organization-Unit: 
                test3
        - Organization-Unit: 
           test2

如何将主OU的引用提供给子OU?

0 个答案:

没有答案