Created
January 27, 2023 14:20
-
-
Save fabiopaiva/12cdcabc64d7b0a813ad32865634e984 to your computer and use it in GitHub Desktop.
Reproduce error TooMany requests when managing several API Gateway resources with Cloudformation using CDK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
import 'source-map-support/register'; | |
import * as cdk from 'aws-cdk-lib'; | |
import { DebugNightlyBuildStack, DebugNightlyBuildStackWithDependency, DebugNightlyBuildWithNestedStacks, DebugNightlyBuildWithNestedStacksWithDependency } from '../lib/debug-stack'; | |
const app = new cdk.App(); | |
new DebugNightlyBuildStack(app, 'DebugNightlyBuildStack'); // this one crashes on delete | |
new DebugNightlyBuildWithNestedStacks(app, "DebugNightlyBuildWithNestedStacks"); // this one crashes on delete | |
new DebugNightlyBuildStackWithDependency(app, "DebugNightlyBuildStackWithDependency"); // this one works | |
new DebugNightlyBuildWithNestedStacksWithDependency(app, "DebugNightlyBuildWithNestedStacksWithDependency"); // this one works |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as cdk from 'aws-cdk-lib'; | |
import { Construct } from 'constructs'; | |
import * as apigateway from 'aws-cdk-lib/aws-apigateway'; | |
const createApi = (scope: Construct, id: string) => { | |
const restApi = new apigateway.RestApi(scope, id); | |
restApi.root.addMethod('ANY'); | |
const method = restApi.root.addResource('pets').addMethod('GET', new apigateway.MockIntegration({ | |
integrationResponses: [{ | |
statusCode: '200', | |
}], | |
requestTemplates: { | |
'application/json': '{ "statusCode": 200 }', | |
}, | |
}), { | |
methodResponses: [{ statusCode: '200' }], | |
}); | |
restApi.methods.push(method); | |
return restApi; | |
} | |
export class DebugNightlyBuildStack extends cdk.Stack { | |
constructor(scope: Construct, id: string, props?: cdk.StackProps) { | |
super(scope, id, props); | |
for (let i = 0; i < 20; i++) { | |
createApi(this, `RestAPI${i}`); | |
} | |
} | |
} | |
class NestedStackAPI extends cdk.NestedStack { | |
constructor(scope: Construct, id: string, props?: cdk.NestedStackProps) { | |
super(scope, id, props); | |
createApi(this, "RestAPI"); | |
} | |
} | |
export class DebugNightlyBuildWithNestedStacks extends cdk.Stack { | |
constructor(scope: Construct, id: string, props?: cdk.StackProps) { | |
super(scope, id, props); | |
for (let i = 0; i < 20; i++) { | |
new NestedStackAPI(this, `NestedAPI${i}`, props); | |
} | |
} | |
} | |
export class DebugNightlyBuildStackWithDependency extends cdk.Stack { | |
constructor(scope: Construct, id: string, props?: cdk.StackProps) { | |
super(scope, id, props); | |
const apis = []; | |
for (let i = 0; i < 20; i++) { | |
apis.push(createApi(this, `RestAPI${i}`)); | |
if (apis[i - 1] !== undefined) { | |
apis[i].node.addDependency(apis[i - 1]); | |
} | |
} | |
} | |
} | |
export class DebugNightlyBuildWithNestedStacksWithDependency extends cdk.Stack { | |
constructor(scope: Construct, id: string, props?: cdk.StackProps) { | |
super(scope, id, props); | |
const stacks = []; | |
for (let i = 0; i < 20; i++) { | |
stacks.push(new NestedStackAPI(this, `NestedAPI${i}`, props)); | |
if (stacks[i - 1] !== undefined) { | |
stacks[i].addDependency(stacks[i - 1]); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment