我正在尝试通过 AWS CLI
创建托管策略:
POLICY='
{
"Version":"2012-10-17",
"Statement":
[{
"Effect":"Allow",
"Action":
[
"cloudformation:*"
],
"Resource":"*"
},
{
"Effect":"Deny",
"Action":
[
"cloudformation:UpdateStack",
"cloudformation:DeleteStack"
],
"Resource": "'${arn}'"
}]
}'
# Create policy if not already created
[ $(aws iam list-policies | grep -ce CloudFormation-policy-${StackName}) -eq 0 ] && (aws iam create-policy --policy-name CloudFormation-policy-${StackName} --policy-document "'${POLICY}'")
当我运行脚本时,出现此错误:
An error occurred (MalformedPolicyDocument) when calling the CreatePolicy operation: Syntax errors in policy.
我不知道错误出在哪里。 有什么想法吗?
最佳答案
每个操作系统都有自己的处理单引号与双引号转义的方式,如 AWS CLI documentation 所示。 :
When passing in large blocks of data, you might find it easier to save the JSON to a file and reference it from the command line. JSON data in a file is easier to read, edit, and share with others.
Quoting Strings传递 Json 数据时,方法可能不是最佳选择,而是使用 Loading parameters from file approach .
关于json - 创建 IAM 策略时出现 MalformedPolicyDocument 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44309441/