{
    "Description": "CloudFormation template creating alarm to monitor and terminate Idle EMR",
    "Parameters": {
        "AlarmName": {
            "Default": "TerminateIDLE-EMRAlarm",
            "Description": "Enter the name of the alarm",
            "Type": "String"
        },
        "EMRJobFlowID": {
            "Description": "Job Flow ID of the cluster to be monitored",
            "Type": "String"
        },
        "EvaluationPeriod": {
            "Description": "M out of N - Input N Value",
            "Type": "String"
        },
        "SNSSubscribeTopic": {
            "Description": "ARN of the SNS Topic that triggers the lambda",
            "Type": "String"
        }
    },
    "Resources": {
        "EMRMonitorAlarm": {
            "Properties": {
                "AlarmActions": [{
                    "Ref": "SNSSubscribeTopic"
                }],
                "AlarmDescription": "Cloudwatch alarm to shutdown the idle EMR instance",
                "AlarmName": {
                    "Ref": "AlarmName"
                },
                "ComparisonOperator": "LessThanOrEqualToThreshold",
                "Dimensions": [
                    {
                        "Name": "JobFlowId",
                        "Value": {
                            "Ref": "EMRJobFlowID"
                        }
                    }
                ],
                "EvaluationPeriods": {
                    "Ref": "EvaluationPeriod"
                },
                "MetricName": "isEMRUsed",
                "Namespace": "EMRShutdown/Cluster-Metric",
                "Period": 300,
                "Statistic": "Average",
                "Threshold": "0"
            },
            "Type": "AWS::CloudWatch::Alarm"
        }
    }
}