AWS malformed policy error
amazon-web-services
Solution
Solved this riddle!
There has to be a `file://` prefix in front of the policy file name:
aws iam put-group-policy --group-name my-group --policy-name s3-full-access --policy-document file:///tmp/policy.json
The original error message is very misleading, as you get the same message if you provide a filename that does not exist at all.
So it is not the syntax of the policy in the file but the fact that the CLI does not see the file at all, that causes the error.
Problem
I am trying to set an AWS group policy via the AWS CLI like so: ``` aws iam put-group-policy --group-name my-group --policy-name \ s3-full-access --policy-document /tmp/policy.json ``` This is the content of /tmp/policy.json: ``` { "Version": "2012-10-17", "Statement": [ { "Action": [ "s3:ListAllMyBuckets" ], "Effect": "Allow", "Resource": "arn:aws:s3:::*" }, { "Action": "s3:*", "Effect": "Allow", "Resource": "arn:aws:s3:::my-bucket*" } ] } ``` I keep getting the following error: ``` A client error (MalformedPolicyDocument) occurred when calling the PutGroupPolicy operation: The policy is not in the valid JSON format. ``` I do not know how to proceed, the error is too unspecific. Anyone able to help?