IAM put-policy-file argument errors are not helpful
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.
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.