question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

By default every new RestApi instance replaces the single CloudWatch Role on API Gateway

See original GitHub issue

We discovered that our API Gateway cloudwatch role was being overwritten by deployments of RestApi constructs. The CloudWatch Role is associated with the API Gateway’s Account resource. The API Gateway only supports 1 role for providing it the permissions required to write to CloudWatch so it seems strange to assume that every RestApi deployed is going to want to create that role and update the API Gateway Account automatically.

The cloudWatchRole property of RestApiProps should default to false.

Reproduction Steps

In an AWS account that has already setup API Gateway’s CloudWatch Role (by whatever means) run:

$ aws apigateway get-account
{
    "cloudwatchRoleArn": "arn:aws:iam::NNNNNNNNN:role/apigateway.amazonaws.com",
    "throttleSettings": {
        "burstLimit": 1050,
        "rateLimit": 2100.0
    },
    "features": [
        "UsagePlans",
        "ArbitraryUsageIdentifierKeys"
    ],
    "apiKeyVersion": "4"
}

Note the cloudwatchRoleArn and deploy a new stack that uses the RestApi construct without providing a value for the cloudWatchRole property. When you run aws apigateway get-account again you will see that the RestApi construct creates a new role and overwrites the role association that was previously established with API Gateway’s Account resource.

Error Log

In our case we found that when the role was replaced our existing api gateway deployments were no longer able to write to cloudwatch logs. Our workaround is to do our best to ensure that nobody creates a RestApi construct without setting the cloudWatchRole property to false.

Environment

  • **CLI Version :cdk version 1.31.0, aws-cli/1.16.260
  • **Framework Version:1.31.0
  • **OS :Mac OS
  • **Language :Typescript

Other


This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
nija-atcommented, Apr 8, 2020

You are correct, in that this is confusing behaviour. The problem is exacerbated by the fact that this property is configured on an instance of RestApi.

Since the API has been out there for a long time and our API Gateway module is stable, we cannot change this default. It will change the behaviour on all new CDK deployments, and customers will not know that this has changed.

A better approach may be to deprecate this property, and add a new property (either in RestApi or as a separate construct) with the correct default and behaviour.

0reactions
github-actions[bot]commented, Jun 21, 2022

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Setting up CloudWatch logging for a REST API in API Gateway
API Gateway replaces overridden request IDs that aren't in the format of a UUID with UUID _REPLACED_INVALID_REQUEST_ID in your access logs. $context.
Read more >
Using AWS CloudWatch | Crosswalk - Pulumi
You can use Amazon CloudWatch Logs to monitor, store, and access your log files from Amazon Elastic Compute Cloud (Amazon EC2) instances, AWS...
Read more >
Security Overview of Amazon API Gateway - Awsstatic
This is the default selection for REST API Gateway endpoints. It should not be used for. APIs where clients consist of other services...
Read more >
AWS Lambda Guide - Serverless.yml Reference
Endpoint type for API Gateway REST API: edge or regional (default: edge) ... all resources in the service except deleting/replacing EC2 instances (use...
Read more >
Enable CloudWatch logs for API Gateway - YouTube
In my this video you will learn how to enable CloudWatch Logs while troubleshooting your API Gateway API.Also I have discussed about a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found