All Tools View Categories About Contact Privacy

AWS CDK IAM Construct Generator

Generate a CDK TypeScript Construct class with a role and per-statement PolicyStatements.

Generates a starting-point CDK construct — review it, especially any NotAction/NotResource TODOs, before deploying. Runs entirely in your browser.

  

About AWS CDK IAM Construct Generator

AWS CDK IAM Construct Generator builds a real, reusable CDK TypeScript Construct class from your pasted policy JSON — not a bare PolicyDocument.fromJson(...) one-liner. It creates an iam.Role trusted by a service principal you choose, then maps every Statement in your policy to its own new iam.PolicyStatement({ effect, actions, resources }) call added to that role via role.addToPolicy(...).

Building with CDK's own PolicyStatement builder API — rather than embedding the whole document as an opaque JSON blob — is what makes the output a proper construct: something you can instantiate more than once, extend with typed props, or unit-test with the CDK assertions library, instead of a single static JSON dump. Effects map to iam.Effect.ALLOW/DENY, Action/Resource lists (whether written as a single string or an array in your JSON) become TypeScript string arrays, and any Condition block is passed straight through as the conditions property.

NotAction/NotResource statements are not silently guessed at — they are emitted as a commented-out TODO with the original statement JSON, since they need a different, lower-level CDK API to represent correctly. The construct class name and trust principal are the two things you choose; everything else is generated. This is still a starting point: review resource ARNs, action lists, and the trust relationship before deploying.

Features

  • Real CDK Construct classexport class ... extends Construct, not a bare snippet.
  • Per-statement PolicyStatement mapping, not a single fromJson() call.
  • iam.Role with a chosen service-principal trust relationship (EC2, Lambda, ECS tasks, and more).
  • Condition blocks carried through to the conditions property.
  • NotAction/NotResource flagged as a TODO instead of silently mis-converted.
  • Works on any valid JSON, with a structural warning if it does not look like a complete IAM policy.
  • One-click copy of the generated TypeScript.
  • 100% client-side — nothing is uploaded.

How to Use

  1. Paste your policy JSON, or click the sample.
  2. Set the construct class name.
  3. Pick the trusted service principal for the role.
  4. Click Generate CDK Construct.
  5. Copy the TypeScript and review it — especially any NotAction/NotResource TODOs — before deploying.

Examples

Example. A two-statement policy (an S3 read Allow and a DeleteObject Deny) with "lambda" selected produces ExampleRoleConstruct, whose role trusts lambda.amazonaws.com, with two role.addToPolicy(new iam.PolicyStatement({...})) calls — one iam.Effect.ALLOW, one iam.Effect.DENY.

Benefits

  • A reusable construct, not a static blob — built with CDK's own builder API.
  • Statement-by-statement fidelity, so each Allow/Deny is inspectable in code review.
  • Flags what it can't safely convert instead of guessing.
  • Real trust-policy generation for common AWS service principals.
  • Private — generation runs entirely in your browser.

Frequently Asked Questions

Is this generated CDK code ready to use as-is?
It is a reasonable starting point, not a guaranteed drop-in. The construct class name and the service principal are placeholders/choices you should adjust to fit your CDK app, and any resource ARNs in your policy JSON are copied through literally — review the generated file like any other CDK code you didn't hand-write.
Why generate a Construct class with individual PolicyStatement calls instead of a one-line PolicyDocument.fromJson()?
A real construct — one you can instantiate multiple times, extend with props, and unit-test with the CDK assertions library — needs each statement expressed with CDK's own builder API (<code>new iam.PolicyStatement({ effect, actions, resources })</code>), not a single opaque JSON blob. That is the difference between this tool and the narrower IAM Policy to CDK Converter, which intentionally uses <code>fromJson()</code> for a quick static embed.
What happens to statements that use NotAction or NotResource?
Those cannot be expressed with the <code>actions</code>/<code>resources</code> properties on <code>PolicyStatement</code> the same way — the tool emits a commented-out TODO with the raw statement JSON instead of guessing, so you can convert it by hand using <code>PolicyStatement</code>'s lower-level methods (e.g. <code>addNotActions</code>/<code>addNotResources</code>).
Are Condition blocks converted too?
Yes — when a statement has a <code>Condition</code> block, it is passed straight through as the <code>conditions</code> property, since CDK's <code>PolicyStatementProps.conditions</code> shape matches the raw IAM JSON Condition shape.
Only TypeScript, or is Python supported too?
Only TypeScript. If you need Python, Java, or C#, use the printed statements as a reference and port them to your language's CDK equivalent by hand.
Does it validate that my JSON is a well-formed IAM policy first?
It only requires valid JSON to generate the construct. If the parsed JSON does not look like a complete IAM policy it still converts, but shows a structural warning above the output.
Is my policy JSON uploaded anywhere?
No — parsing and code generation both run entirely in your browser.