Does anyone have any example of creating a cloudwa...
# aws
Does anyone have any example of creating a cloudwatch anomoly detection alarm with pulumi? Been using awsx exclusively for all metric/alarm needs but can't seem to figure this out.
just using aws.MetricAlarm
like a custom metric and alarm?
Yeah exactly, I've gone with that now. Just referenced the terraform docs for some examples.
Copy code
jenkins_backup_alarm(actions?: string[]) {
        var alarm_actions: any[] = [];

        if (actions) {
            for (let action of actions) {

        var alarm_name = `${this.prefix}-jenkins-backup`;
        var alarm = new aws.cloudwatch.MetricAlarm(alarm_name, {
            namespace: `${}/CUSTOM`,
            name: alarm_name,
            comparisonOperator: "LessThanThreshold",
            threshold: 1,
            statistic: "Maximum",
            period: 86400,
            evaluationPeriods: 1,
            treatMissingData: "breaching",
            metricName: "awsbackup-complete",
            dimensions: {
                environment: this.env.toLowerCase(),
                region: this.region,
            alarmActions: alarm_actions,
            okActions: alarm_actions,
nice, ty
I ended up with the following as I specifically needed an anomaly detection (ie.
Copy code
// alarm on 5xx error rise
    new aws.cloudwatch.MetricAlarm(
      resourceName(['api', '5xx'], service),
        evaluationPeriods: 1,
        metricQueries: [
            id: 'e1',
            returnData: true,
            expression: 'ANOMALY_DETECTION_BAND(m1)',
            label: 'Expected 5xx',
            id: 'm1',
            returnData: true,
            metric: pulumi.output({
              namespace: 'AWS/ApiGateway',
              metricName: '5XXError',
              unit: 'Count',
              stat: 'Sum',
              period: 300,
              dimensions: { ApiName: },
        thresholdMetricId: 'e1',
        alarmActions: [opsTopic],
        okActions: [opsTopic],
        treatMissingData: 'ignore',
        comparisonOperator: 'GreaterThanUpperThreshold',
      { parent: this }