【发布时间】:2018-10-29 22:21:16
【问题描述】:
我在 AWS 组织工作:目前在 AWS 组织下创建 scp 策略,如下所示:
Python 文件:
policies = config['policies']
for policy in policies:
try:
OUPolicy = client.create_policy(
Description=policy['description'],
Name= policy['Name'],
Content=policy['content'],
Type='SERVICE_CONTROL_POLICY'
)
YAML 文件:
policies:
- Name: xyz
description: Service Control Policies for xyz
content:
Version: 2012-10-17
Statement:
- Effect: Allow
Resource: "*"
Action: "*"
- Effect: Deny
Resource: "*"
Action: "*
我验证了 YAML 模板,格式正确,但仍然出现如下错误:
Parameter validation failed:
Invalid type for parameter Content, value: {'Version': datetime.date(2012, 10, 17), 'Statement': [{'Effect': 'Allow', 'Resource': '*', 'Action': '*'}, {'Effect': 'Deny', 'Resource': '*', 'Action': '*'}]}, type: <class 'dict'>, valid types: <class 'str'>
【问题讨论】:
-
看起来好像您没有根据要求将 YAML 文件的内容传递给
client.create_policy。从错误消息的最后一部分猜测,它需要一个字符串而不是字典。我建议您查看该函数的文档。 -
我检查了很多次但无法识别错误..你能帮忙吗?我真的很感激
-
client.create_policy的文档对Content参数有什么看法?除非你告诉我们这个函数的确切来源,否则我们无法知道问题出在哪里。 -
根据 aws boto3 doc : response = client.create_policy( Content='string', Description='string', Name='string', Type='SERVICE_CONTROL_POLICY' )
-
Content (string) -- [必需] 添加到新策略的策略内容。例如,如果您创建服务控制策略 (SCP),则此字符串必须是 JSON 文本,用于指定附加帐户中的管理员可以委派给其用户、组和角色的权限。 .
标签: python aws-sdk-js