创建IAM策略时出现MalformedPolicyDocument错误

时间:2017-06-01 13:51:57

标签: json shell amazon-web-services amazon-cloudformation amazon-iam

我正在尝试按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.

我无法弄清楚错误的位置。 有什么想法吗?

1 个答案:

答案 0 :(得分:1)

每个操作系统都有自己的方法来处理单引号和双引号转义以及AWS CLI documentation

  

传入大块数据时,您可能会发现更容易保存   JSON到文件并从命令行引用它。 JSON数据   在文件中更容易阅读,编辑和与他人分享。

传递Json数据时,

Quoting Strings方法可能不是最佳选择,而是使用Loading parameters from file approach

相关问题