Getting "Invalid json" error when creating iam-role using aws cli

1.6k views Asked by At

I'm getting an error when trying to create a new role using aws cli.

Here is the error message.

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

In other to crate a role, I run following command.

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

and the policy.json is

{
  "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"
        }
      }
    }
  ]
}
1

There are 1 answers

4
Marcin On

You should be using file:// as explained in:

Therefore, you can try the following if policy.json in your current working directory:

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