Search code examples
amazon-web-servicesaws-cdkdatadoginfrastructure-as-code

How to setup DataDog alerts via AWS CDK?


Is it possible to create DataDog alerts & notifications in IaC way via AWS CDK? I want to send notifications in case of any HTTP 500 errors my web service emits.


Solution

  • You can use cdk-datadog-resources like so:

    import { DatadogMonitor } from '@nomadblacky/cdk-datadog-resources';
    
    new DatadogMonitor(yourStack, 'TestMonitor', {
      datadogCredentials: {
        apiKey: process.env.DATADOG_API_KEY!,
        applicationKey: process.env.DATADOG_APP_KEY!,
      },
      query: 'avg(last_1h):sum:system.cpu.system{host:host0} > 100',
      type: MonitorType.QueryAlert,
      name: 'Test Monitor',
      options: {
        thresholds: {
          critical: 100,
          warning: 80,
          oK: 90,
        },
        notifyNoData: true,
        evaluationDelay: 60,
      },
    });