All jobs

Add API Gateway Throttling to an AWS CDK App from a Linear Issue

Yes. An agent picks up the Linear issue, adds stage and per-method throttling to your CDK REST API, writes an assertions test for the limits and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent starts from the Linear issue and the repository, and finds where the API is defined. In a stack like typescript/api-cors-lambda-crud-dynamodb in aws-samples/aws-cdk-examples, index.ts builds a RestApi named Items Service with aws-cdk-lib 2.262.1, adds an items resource with GET and POST and an {id} child with GET, PATCH and DELETE, each backed by a NodejsFunction on Runtime.NODEJS_24_X that reads a DynamoDB Table named items through TABLE_NAME and PRIMARY_KEY environment variables. addCorsOptions attaches a MockIntegration for OPTIONS on both resources. There is no deployOptions on the API, so the stage runs at the account defaults, and no usage plan or API key exists. cdk.json synthesizes with npx tsc && npx tsx index.ts, package.json has build as tsc and a postinstall that installs the lambdas/ package, and jest.config.js is present with @swc/jest and aws-cdk-lib/testhelpers/jest-autoclean but there is no test file yet.

The agent adds throttling at two levels. On the RestApi it sets deployOptions with throttlingRateLimit and throttlingBurstLimit for the whole prod stage, so every method inherits a ceiling, and it adds methodOptions on that same stage for the two write paths that hit DynamoDB hardest, /items/POST and /items/{id}/PATCH, with lower per-method limits. The numbers come from the issue when it states them and otherwise from a ThrottlingConfig interface the agent adds at the top of index.ts with named defaults, so a reviewer changes one object rather than hunting through method calls. The OPTIONS mock methods are left at the stage default, because a CORS preflight that is throttled harder than its POST only produces confusing browser errors.

Because the issue asks for throttling and not for API keys, the agent does not add a UsagePlan; the pull request explains that per-client quotas would need one plus an apiKeyRequired flag on each method, and offers it as a follow-up. It then writes test/api-throttling.test.ts with Template.fromStack, asserting that the AWS::ApiGateway::Stage has MethodSettings containing a */* entry with the stage limits and /items POST and /items/{id} PATCH entries with the method limits, following the repository's SNAPSHOT_TESTING.md convention of assertion tests over raw snapshots where asset hashes would churn. It adds a test script running jest to package.json, since the config exists without one.

In the sandbox it runs npm install, npm run build, npx cdk synth --quiet to prove the stack still synthesizes with the new stage settings, and npx jest. It does not deploy, because a deploy needs AWS credentials and a bootstrapped account the sandbox does not have, and the pull request says so. It links the Linear issue, shows the MethodSettings block from the synthesized template, and lists the default limits with a sentence on how to override them.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "A Linear issue labelled agent says: \"Add throttling to the Items API. The API Gateway stage should have a rate and burst limit for all methods, with tighter limits on POST /items and PATCH /items/{id}. Add a test that checks the limits.\" Do the work in this CDK app: read index.ts, cdk.json, package.json and jest.config.js first, add deployOptions with stage-level throttlingRateLimit and throttlingBurstLimit and methodOptions for the two write methods, keep the limits in one named config object, do not add a usage plan or API keys, and write a jest assertions test with Template.fromStack over the AWS::ApiGateway::Stage MethodSettings. Add a test script if none exists. Run npm run build, cdk synth and jest in the sandbox and quote the output. Open a pull request that links the issue and explains how to change the limits.",
  "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

What comes back is a pull request on its own branch that changes index.ts and package.json and adds test/api-throttling.test.ts. index.ts gains a small throttling config object and deployOptions on the RestApi with stage settings and two methodOptions entries; the Lambda functions, the DynamoDB table and the CORS mock integrations are untouched. The Linear issue is linked from the description.

The description quotes npm run build, npx cdk synth and npx jest output from the sandbox, and pastes the MethodSettings array from the synthesized AWS::ApiGateway::Stage so a reviewer sees the exact ThrottlingRateLimit, ThrottlingBurstLimit, ResourcePath and HttpMethod values without running anything. It states that no deploy was made.

Before merging, a reviewer checks the limits against the API's real traffic and the account-level API Gateway quota, confirms that OPTIONS was deliberately left at the stage default, and runs cdk diff against their own stack to see that the only change is the stage's method settings. Then they merge and deploy through their usual pipeline.

Run it on every Linear issue labelled agent

In the console, an automation with a linear trigger on linear.issue.labeled and the label agent starts one run per labelled issue, with the issue added after the prompt, in the Project's repository. Changes made by an app integration never fire it, so the agent's own comments on the issue do not start another run. Each run reads the CDK app the Project points at, so an app with an HttpApi instead of a RestApi gets the throttling API Gateway v2 supports, with the difference explained in the pull request.

From your own server, the same run is one POST /o/{org}/sessions per issue: put the repository in resources and add the issue's https://linear.app/<workspace>/issue/<ID> URL there too, so Rush reads it through your Linear connection into the prompt. A webhook URL on the API key reports run.completed or run.failed with the session_url when the turn finishes.

The use case this job follows, with its automation and trigger: Turn a Linear label into a PR.

Why run it on Rush?

Throttling settings are easy to set and hard to verify without deploying, and a wrong ResourcePath in methodOptions silently applies nothing. In its own sandbox the agent synthesizes the stack and reads the MethodSettings out of the generated template, then locks them with an assertions test, so the pull request shows the exact CloudFormation that will deploy rather than a description of it. Every cdk synth and jest run is kept in the run's record.

A Linear label turns into a reviewed infrastructure change with a test, on its own branch, with the limits in one place a reviewer can tune. Several API hardening issues can run at once, each in its own sandbox, each with its own pull request.

Frequently asked questions

Does the agent deploy the change?

No. The sandbox has no AWS credentials and the pull request says so. The agent proves the change with cdk synth and an assertions test over the synthesized template; the deploy goes through your usual cdk deploy or pipeline after review.

Why no usage plan or API keys?

Because the issue asks for throttling, which API Gateway applies at the stage and method level without any client identification. Per-client quotas need a UsagePlan, an ApiKey and apiKeyRequired: true on each method, which changes how every caller authenticates. The pull request names that as a separate piece of work.

Where do the numbers come from?

From the Linear issue when it states them. Otherwise the agent uses conservative defaults in a single named config object at the top of index.ts, with the stage limits above the per-method limits, and the description tells you to change that object. The test reads the same object, so changing a number does not break it.

Will the existing Lambda functions or the DynamoDB table change?

No. Throttling lives on the API Gateway stage, so the five NodejsFunction definitions, their bundling options and the items table are untouched. cdk diff on the pull request shows only the stage's MethodSettings.

More AWS CDK jobs

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

Keep reading