我正在尝试使用cli-input-json为cli命令提供json作为输入来创建组策略。 命令是
aws iam put-group-policy --cli-input-json file://D:\\json\\demo\\json
grpPolicy_testpolicy1.json
给出以下错误
A client error (MalformedPolicyDocument) occurred when calling the PutGroupPolicy operation: The policy is not in the valid JSON format.
D:\ json \ demo \ json中json文件的内容 grpPolicy_testpolicy1.json
{
"GroupName": "testgroup11",
"PolicyName": "testpolicy11",
"PolicyDocument": "file://D:\\json\\policypermission.txt"
}
D:\ json \的政策文件档案内容 policypermission.txt
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "uploadandgetfromS3",
"Effect": "Allow",
"Action": [
"s3:CreateBucket",
"s3:CreateObject",
"s3:GetObject",
"s3:GetObjectAcl",
"s3:ListAllMyBuckets",
"s3:ListBucket",
"s3:PutBucketAcl",
"s3:PutObject",
"s3:PutObjectAcl",
"rds:DescribeDBLogFiles",
"rds:DownloadDbLogFilePortion"
],
"Resource": "*"
}
]
}
我已经验证了所有json文件的json有效性,但仍然知道cli说政策文件格式错误。 我还使用普通的cli命令创建并附加了上述政策,以确认政策文件的有效性,并且运作良好。
答案 0 :(得分:1)
{
"GroupName": "testgroup11",
"PolicyName": "testpolicy11",
"PolicyDocument": "file://D:\\json\\policypermission.txt"
}
虽然这在概念上有意义,但我认为AWS Command Line Interface (AWS CLI)在这里不支持对file://
这样的URL的内联/嵌套引用,而只是作为命令行参数,例如:
aws iam put-group-policy --cli-input-json file://D:\\json\\demo\\json \
grpPolicy_testpolicy1.json --policy-document file://D:\\json\\policypermission.txt
这样可行,因为命令行参数优先于指定为CLI Input JSON Parameters的参数。但是,一旦您未指定覆盖--policy-document
,JSON解析器将跳过内联PolicyDocument
元素,在该元素中,它需要内联JSON对象,但会遇到URL file://D:\\json\\policypermission.txt
。