amazon-web-servicesamazon-cloudwatchaws-cdk

Specify AWS region for metrics in cdk-monitoring-constructs


I have 3 dyanmodb tables each in a different AWS region. I want to use cdk-monitoring-constructs to monitor them and have metrics for each dyanmodb table on the same dashboard. I create my monitoring facade and then iterate over my regions like so:

for (const region of regionsToMonitor) {

 const dyanmodbToMonitor = tableMap.get(region)
 monitoring.monitorDynamoTable(
     {
          table: dyanmodbToMonitor
      }
  )

however this only works for my table created in us-east-1. The other two tables, one in EU and the other in us-west-2 have missing metrics in the resulting dashboards. I can see in the cloudwatch metrics source for these two tables that they're empty because they're using the wrong region (i.e. using us-east-1 instead of us-west-2):

{
    "view": "timeSeries",
    "title": "Latency (Average)",
    "region": "us-east-1",

and when I manually change the region in their definitions the metrics appear.

How can I specify which region should be used when adding these tables to monitored?


Solution

  • TL;DR

    Unfortunately, you can not create a graph with metrics from another region via cdk-monitoring-constructs. The current implementation doesn't support it.


    I found this question interesting, so I traced the code and realised the current implementation doesn't pass the region to GraphWidget.

    Here are the lines of code that show how aws-cdk defines the props of GraphWidget.

    export interface MetricWidgetProps {
      ...
      /**
       * The region the metrics of this graph should be taken from
       *
       * @default Current region
       */
      readonly region?: string;
      ...
    }
    

    Here are the lines of code that show how cdk-monitoring-constructs generates graphs.

    return new GraphWidget({
      width,
      height,
      title: "Read Usage",
      left: [this.consumedReadUnitsMetric, this.provisionedReadUnitsMetric],
      leftYAxis: CountAxisFromZero,
      leftAnnotations: this.dynamoReadCapacityAnnotations,
      right: [this.readCapacityUsageMetric],
      rightYAxis: PercentageAxisFromZeroToHundred,
      legendPosition: LegendPosition.RIGHT,
    });
    

    As you can see, it doesn't pass the region argument to GraphWidget, this result the graph is always created with the metrics in the current region (CloudFormation Stack region).