aws-cli icon indicating copy to clipboard operation
aws-cli copied to clipboard

IAM put-policy-file argument errors are not helpful

Open khanklatt opened this issue 8 years ago • 1 comments

When running a command like: $ aws iam put-user-policy --user-name u --policy-name p --policy-document ./x.json

The error you get is "An error occurred (MalformedPolicyDocument) when calling the PutUserPolicy operation: Syntax errors in policy."

The actual error is that x.json can not be a local unix file system path. The error should look more like:

"An error occurred (Invalid policy URI protocol) when calling the PutUserPolicy operation: expected URI prefix 'file://', got './x.json'"

The same error for an actual malformed JSON file should not be shared with an inability to locate/upload an actual JSON policy file.

khanklatt avatar Aug 10 '18 22:08 khanklatt

Hey @khanklatt, thanks for reaching out to us. The error you're receiving on your put-user-policy command is technically correct since the --policy-document flag will accept a JSON document as a string (e.g. $ aws iam put-user-policy --user-name username --policy-name test --policy-document '{"Version": "2012-10-17","Statement": [{"Sid": "GrantAllSTS","Effect": "Allow","Action": "sts:*","Resource": "*"}]}') in addition to accepting local files with the appropriate file:// URI.

Unfortunately this isn't made explicitly clear in the documentation page for this command, we'll be updating this page to clarify this point.

diehlaws avatar Aug 15 '18 00:08 diehlaws