[@aws-cdk/aws-apigateway] Getting 429 from APIGateway when trying to deploy the stack
:question: General Issue
The Question
I'm forced to use older version of CDK constructs (1.32.2), in combination with OpenAPI rest API definition. As a result, I can't use latest SpecRestApi.
I'm tryin to achieve similar results, by combining sam.CfnApi with apigateway.Cfn constructs. When I'm trying to deploy the stack, I keep getting errors like this:
Invalid request provided: Too Many Requests (Service: ApiGateway, Status Code: 429, Request ID: XXXXXX, Extended Request ID: null)
Though experimentation, I figured out that this is the code that causes the error:
const apigDomain = new apig.CfnDomainName(this, 'DomainName', {
regionalCertificateArn: props.certificate.certificateArn,
domainName: props.domain,
endpointConfiguration: {
types: ['REGIONAL'],
},
});
api.addDependsOn(apigDomain);
Without it, CfnApi is created just fine. Surprinsingly I cannot find any mentions of CloudFormation getting throttled by APIGateway. Any hints?
Environment
- CDK CLI Version: 1.51.0
- Module Version: 1.32.2
- Node.js Version: 12
- OS: all
- Language (Version): TypeScript (3.8.3)
I don't know if this is a new bug on CloudFormation's and API Gateway's side, as a CF stack that was deploying successfully for us, stopped working with the same error:
Invalid request provided: Too Many Requests (Service: ApiGateway, Status Code: 429, Request ID: 17f0fe0f-7974-490d-b728-adf86597357f, Extended Request ID: null)
The resource in the template triggering that error is a custom domain:
CustomDomainName:
Type: 'AWS::ApiGateway::DomainName'
Properties:
CertificateArn: !Ref CertificateArn
DomainName: !If [ IsProd, !Join [ '', [ 'api.', !ImportValue HostedZoneName ] ], !Join [ '', [ !Ref Stage, 'api.', !ImportValue HostedZoneName ] ] ]
Let me know if the full template is useful for this but I think it points to the same issue from @podoprigo
FWIW I got the same bug and google searching brought me here. I'm not even using CDK so it seems like a CloudFormation bug. Here's the snippet of my SAM template:
"Globals": {
"Api": {
"OpenApiVersion": "3.0.1",
"EndpointConfiguration": "REGIONAL",
"Domain": {
"CertificateArn": { "Ref": "DomainCertificateArn" },
"DomainName": { "Ref": "DomainName" },
"Route53": {
"HostedZoneId": { "Ref": "DomainZoneId" }
},
"EndpointConfiguration": "REGIONAL",
"BasePath": [ "/app" ]
}
},
...
I guess the upside is that the error was intermittent. A redeploy resulted in success. /shrug
Also, only reason I'm using globals is because CloudFormation kept giving an error about a missing StageName when I declared a Serverless::Api directly even though I had a StageName in the Api. /shrug
Seems like more than a few CloudFormation bugs are sneaking through as of late.
Unfortunately, this seems to be an issue with API Gateway. Please reach out to AWS Support regarding this.
Related to this issue in CloudFormation: https://github.com/aws-cloudformation/aws-cloudformation-coverage-roadmap/issues/588.
So you need to ensure a 30 seconds window between each API call.
In my case, we deployed the same CF Stack multiple times (over 20 times already) as we use it as the base template for new accounts and we never had this issue so we are pointing to a bug or an issue as pointed out by @nija-at
This issue is not related to CDK or CloudFormation. After checking this issue, the same error message "Too Many Requests" will also display on AWS console if you want to change the settings to two Custom Domain and the timing is too close. Even the CloudFormation status of Custom Domain resource is "UPDATE_COMPLETE", you could check the status of Custom Domain in AWS console's API Gateway page and the status is still "UPDATING". On the other hand, adding DependsOn in CloudFormation is not able to resolve this situation. As a result, if you put two Custom Domain resource in the same CloudFormation and you want to change both settings of Custom Domain, you will need to change them one by one. After deploying first Custom Domain settings you see the Status of first Custom Domain is change to "AVAILABLE", and then you could start to change the settings of second Custom Domain.
As a result, if you put two Custom Domain resource in the same CloudFormation and you want to change both settings of Custom Domain, you will need to change them one by one
It works when the stack already exists. What about expansion in a new region - do we need to put some hacky flags in place to only create one domain first? This is not logical, and CF must be able to handle retries or add an ability to actually 'sleep' in between resources.
Unfortunately, this seems to be an issue with API Gateway. Please reach out to AWS Support regarding this.
No it's not a problem with APIG. Their API limits are clearly stated here: https://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html. The problem is that neither CDK nor CF currently have a solution for that. Which results in flaky stack deployments (for example, a stack with 2 APIG domains may succeed on deployment, but will fail on deletion, just because of bad timing).
you can find a proposed solution here what will add a delay in between resources: https://github.com/aws-cloudformation/aws-cloudformation-coverage-roadmap/issues/589
I understand there are limits to what aws-cdk developers can do to resolve issues with other AWS service owners but I've seen a few different issues on this project where the same developer has closed and communicated poorly with the community. You have to realize that there are paying AWS customers behind these issues and as an AWS employed developer you can act as a bridge between cdk and cloudformation which is a completely opaque AWS service. It's extremely frustrating to see multiple issues about the same problem being closed prematurely.
In fact, I am currently working on a cdk project that was created and developed by AWS Proserve which is producing this issue. This is embarrassing to say the least.