1

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
  • How did it go? The issue still persist? Commented Jun 13, 2021 at 20:44

1 Answer 1

4

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 
Sign up to request clarification or add additional context in comments.

4 Comments

But, if the policy.json file is in specific directory in current directory, how to point the path?
@Venus713 You can provide full path to it. For example if its in /tmp/ you can file:///tmp/policy.json. The link in the answer has more examples.
aws iam create-role --path /service-role/ --role-name test-role --assume-role-policy-document file:///src/actions/export/server/role-trust-policy.json I run the command above and got following error. Error parsing parameter '--assume-role-policy-document': Unable to load paramfile file:///src/actions/export/server/role-trust-policy.json: [Errno 2] No such file or directory: '/src/actions/export/server/role-trust-policy.json'
@Venus713 probably you have wrong path. If /src/actions/export/server/role-trust-policy.json actually exists, the command is correct.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.