# Add cdk-nag Checks to an AWS CDK App

Yes. An agent adds cdk-nag AwsSolutions checks to your CDK app, fixes the findings worth fixing, suppresses the rest with reasons and a test, in a pull request.

[Run this on Rush](https://cloud.getrush.ai/run/add-cdk-nag/aws-cdk/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the app and the repository's own precedent before adding the checks. In a CDK app like `typescript/api-cors-lambda-crud-dynamodb` in aws-samples/aws-cdk-examples, `index.ts` defines one stack: a DynamoDB `Table` named `items` with `RemovalPolicy.DESTROY`, five `NodejsFunction`s on `Runtime.NODEJS_24_X` bundled from `lambdas/`, each granted `grantReadWriteData` on the table even though two of them only read, a `RestApi` called `Items Service` with no stage logging or request validation, and an `addCorsOptions` helper that answers `OPTIONS` with `Access-Control-Allow-Origin: '*'` through a `MockIntegration`. `package.json` pins `aws-cdk-lib` 2.262.1, `aws-cdk` 2.1133.0 and Jest 30 with `@swc/jest`, `jest.config.js` matches `**/*.test.ts` and loads `aws-cdk-lib/testhelpers/jest-autoclean`, but there is no test file and no `test` script. `cdk.json` runs `npx tsc && npx tsx index.ts`. Two other examples in the same repository already use cdk-nag: `typescript/connect-cdk` pins `cdk-nag` at `^2.30.0`, and `typescript/imagebuilder/lib/imagebuilder-stack.ts` calls `NagSuppressions.addResourceSuppressions` with reasons, so the convention exists and the agent follows it.

It adds `cdk-nag` as a dev dependency at the version `connect-cdk` uses, and in `index.ts` applies `Aspects.of(app).add(new AwsSolutionsChecks({ verbose: true }))` before `app.synth()`. Then it runs `cdk synth` the way CI does, through `scripts/build-typescript.sh`, which runs `npm ci`, `npm run build`, `npm test` if present and then `scripts/synth.sh` with the repository's `fake.context.json` in `us-east-1`. The synth prints every `AwsSolutions` finding with its construct path, and the agent sorts them into two piles: what the stack should do, and what the example is deliberately not doing.

The first pile is fixed in code. The table gets point-in-time recovery, which is one property. The API stage gets access logging to a new log group and a request validator on the `POST` and `PATCH` methods, both ordinary `RestApi` options. The two read-only functions, `getOneItemFunction` and `getAllItemsFunction`, are changed from `grantReadWriteData` to `grantReadData`, which narrows their IAM policy and is a correctness fix the rule surfaced. The second pile is suppressed, each with a reason a reader can check: the methods have no authorizer because the README describes an open demo API, the wildcard CORS origin is documented in the README with a warning, the Lambda execution role uses the AWS managed basic policy that `NodejsFunction` attaches, and the table's `DESTROY` removal policy is commented in the source as not for production. Suppressions go on the specific resource, through `NagSuppressions.addResourceSuppressions` with `applyToChildren` where the construct wraps the role, never on the whole stack.

Then it makes the check permanent. A new `index.test.ts` builds the stack in a fresh `App`, applies `AwsSolutionsChecks`, and asserts with `Annotations.fromStack(stack).findError` that no `AwsSolutions-*` error remains unsuppressed, and a second assertion checks that every suppression carries a reason longer than a few words. `package.json` gains a `test` script running `jest`, so `scripts/build-typescript.sh`'s `npm run --if-present test` line starts running it in the pull request workflow. The agent adds a short section to the example's `README.md` on what cdk-nag enforces and how to read a new finding, runs the build script end to end once more, and opens the pull request.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Do the work the Linear issue describes: add cdk-nag to this CDK app. Read package.json, cdk.json, tsconfig.json, jest.config.js, index.ts, lambdas/package.json, README.md, and how the repository already uses cdk-nag in typescript/connect-cdk/package.json and typescript/imagebuilder/lib/imagebuilder-stack.ts, plus scripts/build-typescript.sh and scripts/synth.sh first. Add cdk-nag as a dev dependency at the version connect-cdk pins, and apply AwsSolutionsChecks with verbose true to the app in index.ts before synth. Run the build the way scripts/build-typescript.sh does, ending in cdk synth with the fake context, and read every AwsSolutions finding. Fix in code what the stack should do: point-in-time recovery on the table, access logging and a request validator on the API, and grantReadData instead of grantReadWriteData for the two read-only functions. Suppress the rest on the specific resource with NagSuppressions.addResourceSuppressions and a reason a reviewer can verify, citing the README where it documents the open API and the wildcard CORS origin; never suppress at stack level. Add index.test.ts that builds the stack with the checks applied and asserts via Annotations.fromStack that no AwsSolutions error is left and that every suppression has a reason, and add a test script to package.json so the repository's build script runs it. Document the checks in README.md, run the build script once more end to end, and open a pull request listing each finding and whether it was fixed or suppressed.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

The result is a pull request on its own branch changing `index.ts`, `package.json` and `package-lock.json`, `README.md`, and adding `index.test.ts`. Its description is a table of every `AwsSolutions` rule the synth reported, one row each, with the construct path and either the fix applied or the suppression reason, so the review is a read of that table against the diff rather than a hunt through the template.

The transcript keeps both synth runs, the one that produced the findings and the one after the changes that produced none, and the Jest run with the new test green. `GET /o/{org}/p/{project}/sessions/{id}/changes` returns the diff, and the session's `result` holds the same findings table the pull request shows.

A reviewer checks three things before merging: that each suppression names a resource rather than the stack, that each reason points at something true in the README or the source, and that the narrowed grants still cover what `lambdas/get-one.ts` and `lambdas/get-all.ts` actually call. A follow-up on the same session can switch to the `HIPAASecurityChecks` or `NIST80053R5Checks` pack if that is the standard the team is held to.

## Run it on every Linear issue labelled agent

Add an automation to the Project with this prompt and a `linear` trigger on `linear.issue.labeled` with the label your team uses. The issue is appended to the prompt, so one that names the rule pack, or lists findings the team has already decided to accept, steers the run without an edit to the prompt text. A label set by an app integration never fires the trigger, and `max_runs_per_hour` caps how many runs start in an hour.

From your own server, send `POST /o/{org}/sessions` with the repository and the issue URL in `resources`, read through your Linear connection, and a `request_id` that is a UUID v5 of the issue id so a retried webhook does not start a second run. A `webhook_url` on the key receives `run.completed` with `data.session_url` when the pull request is open.

## Why run it on Rush?

Adding cdk-nag is one line; the work is the first synth, which turns a clean stack into a list of findings that someone has to read, judge and either fix or suppress with a reason. Done on a laptop, that reading gets cut short and the result is a stack-level suppression that silences the tool. In its own sandbox the agent runs the build script CI runs, reads every finding against the source and the README, and writes a reason per resource, with both synth outputs kept in the transcript.

The test it adds makes the pull request workflow enforce the checks on every later change, so the finding list never grows silently again. Several CDK apps can be brought under the same checks at once, each run reading its own stack, and each arriving as its own pull request with its own findings table.

## Frequently asked questions

### Will it suppress everything to make the build pass?

No. The prompt separates fixes from suppressions and forbids stack-level suppressions. Point-in-time recovery, API access logging, request validation and the narrowed read grants are code changes; only findings that contradict what the README documents as intentional, the open API and the wildcard CORS origin, are suppressed, each on its resource with a reason.

### Which rule pack does it use?

`AwsSolutionsChecks`, the general pack and the one the repository's other examples already apply. The HIPAA, NIST and PCI packs are a one-line swap in `index.ts` and the test, and a follow-up on the same session can make it.

### Does it change what the stack deploys?

Yes, in four small ways it lists: the table gains point-in-time recovery, the API stage gains an access log group and a request validator, and two Lambda roles lose write permissions they never used. Everything else, including the `DESTROY` removal policy the source comments on, is unchanged and suppressed with that comment as the reason.

### How do the checks keep running after this pull request?

The new `index.test.ts` fails if an `AwsSolutions` error is left unsuppressed, and `package.json` gains a `test` script, so `scripts/build-typescript.sh`, which already runs `npm run --if-present test` before `cdk synth`, runs it on every pull request that touches the example.

### Does the synth need AWS credentials?

No. `scripts/synth.sh` copies the repository's `fake.context.json` in when no `cdk.context.json` exists and sets `AWS_DEFAULT_REGION` to `us-east-1`, which is enough for this stack to synthesize. The agent runs exactly that, with no account access.

## More AWS CDK jobs

- [Add CloudWatch Alarms to an AWS CDK Stack](https://getrush.ai/run/add-cloudwatch-alarms/aws-cdk/)
- [Add Cognito Authentication to an API Gateway in AWS CDK](https://getrush.ai/run/add-cognito-auth/aws-cdk/)
- [Add a Dead Letter Queue to a Lambda in AWS CDK from a Linear Issue](https://getrush.ai/run/add-dlq/aws-cdk/)

## More jobs like this: Turn a Linear label into a PR

- [Add Chat Export to an AI SDK Chatbot](https://getrush.ai/run/add-chat-export/ai-sdk/)
- [Add Chat Export to a Reflex Chat App](https://getrush.ai/run/add-chat-export/reflex/)
- [Add Chat History Export to a Streamlit App from a Linear Issue](https://getrush.ai/run/add-chat-export/streamlit/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
