Boto3 目录服务:create_microsoft_ad 失败

Boto3 DirectoryService: create_microsoft_ad fails

我正在尝试使用 python 中的 boto3 库创建 Microsoft AD。我可以从 AWS 控制台创建它,但是当我尝试使用我从控制台尝试时使用的相同值从我的脚本执行它时,它失败并出现以下错误:

botocore.errorfactory.ClientException: An error occurred (ClientException) when calling the CreateMicrosoftAD operation: Invalid VPC ID. : RequestId: <id>

异常响应的 HTTP 状态代码为 400。

我已按照其提到的 here for windows and the user it belongs to has the permissions mentioned here 方式将访问密钥保存在本地,用于 CreateMicrosoftAD。 (由于这是一个测试设置,我已授予用户完全访问权限。)

脚本如下:

import boto3
client = boto3.client('ds', region_name='us-west-2')
response = client.create_microsoft_ad(
    Name='test1.test2.com',
    ShortName='test1',
    Password='TestPassword1',
    Description='test description',
    VpcSettings={
        'VpcId': 'vpc-1234abcd',
        'SubnetIds': [
        'subnet-1235abcd',
        'subnet-1236abcd'
        ]
    }
)

我在此处为 VPC 和子网 ID 添加了模拟值,但我在控制台中验证了我正在使用可用 VPC 和子网的 ID。 create_microsoft_ad 调用如前所述完成 here

我不确定我是否遗漏了 IAM 用户设置或脚本中的步骤。如果我需要提供更多信息,请告诉我。谢谢!

可能在 AWS 控制台中,您使用的区域不同于 us-west-2

Boto3 使用了错误的凭据。请参阅:Configuring Credentials 配置凭据。你用的是Boto2的。