json - 创建 IAM 策略时出现 MalformedPolicyDocument 错误

标签 json shell amazon-web-services aws-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.

我不知道错误出在哪里。 有什么想法吗?

最佳答案

每个操作系统都有自己的处理单引号与双引号转义的方式,如 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/

相关文章:

json - MongoDB - 动态更新嵌套数组中的对象

javascript - 在python服务器端解析json

bash - 普罗米修斯:zsh:未找到匹配项:server.remoteWrite[0].url

amazon-web-services - 实际上,如何设置Amazon AWS以使其自动缩放?

amazon-web-services - 您请求的 vCPU 容量超过了当前的 vCPU 限制 0

json - 使用 json 模式的 Angular 4 动态组件加载

python - 在while循环中使用线程会导致LED闪烁的问题

bash - 如果 heredoc 命令失败,如何退出脚本

c# 执行 shell 命令并获取结果

amazon-web-services - Amazon Lex 不会将用户和 Lex 之间的对话传递给 amazon connect