Amazon web services 获得;无效的json“;使用aws cli创建iam角色时出错

Amazon web services 获得;无效的json“;使用aws cli创建iam角色时出错,amazon-web-services,aws-cli,assume-role,Amazon Web Services,Aws Cli,Assume Role,尝试使用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-do

尝试使用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"
        }
      }
    }
  ]
}

您应该使用
文件://
,如中所述:

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

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

@Venus713没问题。如果答案有帮助,我们将不胜感激。如果需要,您必须单击upvote/donvote按钮下的“勾号”符号才能接受。但是,如果policy.json文件位于当前目录的特定目录中,如何指向路径?@Venus713您可以提供其完整路径。例如,如果它位于
/tmp/
中,则可以
file:///tmp/policy.json
。答案中的链接有更多示例。
aws iam创建角色--路径/服务角色/--角色名称测试角色--假设角色策略文档file:///src/actions/export/server/role-trust-policy.json
我运行上面的命令,得到以下错误<代码>分析参数“--假定角色策略文档”时出错:无法加载参数文件file:///src/actions/export/server/role-trust-policy.json: [Errno 2]没有这样的文件或目录:'/src/actions/export/server/role trust policy.json'@Venus713您可能有错误的路径。如果
/src/actions/export/server/role trust policy.json实际存在,则该命令是正确的。它是如何运行的?这个问题仍然存在吗?