(@aws-cdk/aws-apigateway): CloudWatch log role ARN references non-existent IAM Role after API deletion #12769
Labels
@aws-cdk/aws-apigateway
Related to Amazon API Gateway
bug
This issue is a bug.
needs-triage
This issue or PR still needs to be triaged.
Hi there! We observed a strange behaviour when deleting APIs via cdk: The API Gateway service itself is unable to push logs to Cloudwatch because it references a IAM role that is already deleted.
Reproduction Steps
Let's start with a simple project:
When deploying this stack, cdk will create two IAM roles (one for each API) to allow pushing logs to Cloudwatch:
After the deployment the latest deployed IAM role is configured in the API Gateway's global settings:
Please note, that the configured ARN is the ARN of the IAM role which was created by "MyRestApi2":
Now I remove the API "MyRestApi2" in the code and redeploy the stack. The API and the IAM role are deleted:
What actually happened?
But the API Gateway is still configured with the role ARN of the deleted IAM Role from "MyRestApi2":
Now API Gateway is globally unable to push logs to Cloudwatch, because it references a non-existent IAM role.
What did you expect to happen?
When deleting APIs cdk should take care of the IAM role ARN configured in the API Gateway. Since I do not expect cdk to "remember" what ARN was configured before the latest deployment, it would be better to remove this behaviour altogether(?). It does not make sense to me that each deployment of a new API reconfigures the API Gateway itself. Every time we deploy a new API the IAM role ARN will change.
It should be the account owner's responsibility to define a IAM role and configure it in the API Gateway. This is a one-time action.
Furthermore each single API in the stack creates its own IAM role with the same policy (AmazonAPIGatewayPushToCloudWatchLogs) over and over again. In this example only two roles were created. In our dev environment there are ~50 APIs deployed and therefore ~50 IAM roles are created. But API Gateway can reference just one IAM role ARN and therefore only one IAM role would be sufficient. It does not seem that much, but these unnecessary IAM roles count towards the account limit. This is one more argument to think about when judging this bug.
Environment
This is 🐛 Bug Report
The text was updated successfully, but these errors were encountered: