How do you add a comment to a json IAM policy?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
AWS IAM policies are JSON documents, and standard JSON does not support comments. That means you cannot insert slash comments or hash comments directly into the policy body and still expect IAM to accept it. The practical solution is to keep the deployed JSON valid while putting human-readable explanation in places IAM and your team can both work with.
Why JSON Comments Fail
IAM policy parsing starts with JSON parsing. If the document is not valid JSON, IAM never gets as far as evaluating the permissions.
A valid IAM policy looks like this:
If you add //, #, or block-style comments directly into that document, the file stops being valid JSON and the policy cannot be used.
Use Sid for Short In-Document Meaning
IAM does give you one field that helps readability: Sid. It is not a free-form comment system, but it is a useful short label for a statement's purpose.
A descriptive Sid such as AllowCiReadBuildArtifacts is much more useful than values like Stmt1 or PolicyPartA.
Put Long Explanations in Infrastructure Code
If the policy is managed through Terraform, CloudFormation, CDK, Pulumi, or another infrastructure tool, put the longer explanation next to the policy definition in that source code.
That keeps the deployed document valid while preserving the reasoning in version-controlled source.
Use Pull Requests and Policy Simulation
When inline comments are not available, review workflow becomes even more important. A good practice is to combine descriptive Sid values with:
- a pull-request explanation
- ticket or incident references
- IAM policy simulation
Example simulation command:
That turns the discussion from "what does this JSON mean" into "what behavior does this policy actually allow."
Keep Policies Small Enough to Understand
Large, mixed-purpose statements are hard to explain even with good Sid values. Smaller statements with a focused purpose are easier to:
- review
- audit
- simulate
- remove later
If you find yourself wanting large comment blocks inside the policy, that is often a sign the policy should be broken into smaller, more purposeful units.
Use Metadata Outside the Policy Body
If your process truly needs rich human commentary, keep that metadata outside the JSON:
- in the repository README
- in architecture docs
- in the IaC source file
- in pull request history
- in policy naming conventions
That makes the explanation durable without making the policy invalid.
Common Pitfalls
The biggest pitfall is trying to insert comment syntax directly into IAM policy JSON. That simply makes the document invalid.
Another common issue is wasting the Sid field on meaningless labels. If you only get one short descriptive field, it should carry useful intent.
Teams also sometimes keep the policy valid but store the rationale only in someone's memory, which makes future audits and incident review much harder.
Summary
- IAM policy JSON does not support inline comments because JSON itself does not support comments.
- Use descriptive
Sidvalues as short intent labels inside the policy. - Put detailed explanations in Terraform, CloudFormation, CDK, or other surrounding source files.
- Use pull requests and IAM simulation to document and verify permission intent.
- Keep policies focused enough that their purpose is understandable without needing fake comments in the JSON body.
Related reading
- How do you add CloudFront in front of API Gateway
- How do you add swap to an EC2 instance?
- How do you call the data model of DynamoDB and Cassandra?
- How do you comment out lines in AWS CLI config and credentials files?
- How do you create an EC2 instance with multiple key pairs?
- How do you delete an AWS CloudWatch metric?
- How do you delete an AWS ECS Task Definition?
- How do you delete an AWS EMR Cluster?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.