Home > Back-end >  CloudWatch metrics graph with condition on date of metric
CloudWatch metrics graph with condition on date of metric

Time:12-01

Is it possible to access the date of the metric from a math expression in a custom CloudWatch graph, to be used in a IF(...) condition?

Background: I've made a custom CloudWatch graph showing the cost of a lambda, by calculating it from two standard metrics for invocations and duration. The expression uses the pricing formula published by AWS, such as duration/1000*0.0000166667*0.50 invocations*0.000002, to give the cost in $ per the summed duration and invocations over a period.

However, this formula depends on the memory allocated to the function, which in this example is 512 MB ("0.50" factor in the expression). On a given date, some functions were reconfigured to get more RAM, and I want to reflect this in the graphs by doing something like (if date > 2021-11-27 then 1.0 else 0.5) to get the multiplying factor for the cost calculation. Is this possible?

CodePudding user response:

Sure - check our the metric math docs. You can use EPOCH, which is the unix timestamp in seconds. There are also YEAR, MONTH, DATE, DAY, HOUR, MINUTE, but they're not that useful in this case.

duration/1000*0.0000166667 * IF(EPOCH(duration)>1637971200, 1.0, 0.5)   invocations*0.000002 

1637971200 is the unix timestamp for 2021-11-27.

  • Related