使用AWS CLI创建IAM角色时出现``无效的JSON''错误

问题描述

尝试使用aws cli创建新角色时出现错误

这是错误消息。

An error occurred (MalformedPolicyDocument) when calling the CreateRole operation: This policy contains invalid Json

在其他方面,我运行以下命令。

aws iam create-role --path /role-service/ --role-name Test-Role --assume-role-policy-document policy.json 

policy.json是

{
  "Version": "2012-10-17","Statement": [
    {
      "Sid": "","Effect": "Allow","Principal": {
        "Service": "cognito-idp.amazonaws.com"
      },"Action": "sts:AssumeRole","Condition": {
        "StringEquals": {
          "sts:ExternalId": "d611c8fd-0fd1-469a-a5ea-b02186042023"
        }
      }
    }
  ]
}

解决方法

您应该按照以下说明使用file://

因此,如果policy.json在当前工作目录中,您可以尝试以下操作:

aws iam create-role --path /role-service/ --role-name Test-Role --assume-role-policy-document file://policy.json