Syntax error in policy, while running 'iam create-policy', but there is no syntax mistake
0
Hi,
Im trying to create "revoke" session policy for iam user using command aws iam create-policy --policy-name "revoke-session" --policy-document JSON.json
And the content of the JSON.json
is
{
"Version": "2012-10-17",
"Statement": {
"Effect": "Deny",
"Action": "*",
"Resource": "*",
"Condition": {"DateLessThan": {"aws:TokenIssueTime": "2022-03-23T15:30:00Z"}}
}
}
But if i run the command it says An error occurred (MalformedPolicyDocument) when calling the CreatePolicy operation: Syntax errors in policy.
If i create exact same policy trough AWS console everything works!
So, im confused, what can be wrong?
asked 2 months ago23 views
1 Answers
1
Accepted Answer
--policy-document
, by default, takes the actual JSON content of the policy. To have the CLI read the content from a file, modify your command to use: --policy-document file://JSON.json
.
(As issued, your command is passing JSON.json
as the body of the policy document, which is why the service rejects it.)
Relevant questions
MalformedPolicyDocument error on PutUserPolicy while running ansible script to generate IAM user along with policy
Accepted Answerasked 3 months agoIAM Policy SFTP
asked 3 years agoAWS Polly Policy json for polly:SynthesizeSpeech IAM
asked 3 months agoIam policy for AWS ecs task role for RDS db connection
asked 22 days agoPolicy IAM user Appstream2.0
asked a month agoAccidentally add in restricted IAM policy, block all access to AWS console
asked a year agoAWS create-policy MalformedPolicyDocument
asked a year agoHow to define IAM::Policy in SAM template
asked 10 months agoMisleading AWS doc: can't create Policy for SAML's role
asked 3 years agoSyntax error in policy, while running 'iam create-policy', but there is no syntax mistake
Accepted Answerasked 2 months ago
thank you!