# Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: MIT-0 AWSTemplateFormatVersion: 2010-09-09 Description: > This template deploys the service alarms. Metadata: version: 1.0.0 Parameters: pApp: Description: Name of the Application to which the resource belongs Type: String pCloudWatchAlarmFlag: Description: This parameter defines if we need a cloudwatch alaram. Type: String pClusterName: Description: The short name or full Amazon Resource Name (ARN) of the cluster on which to run your service. Type: String pFargateServiceName: Description: Fargate Service Name Type: String pIteration: Description: An integer used to distinguish between instances of the same resource in support ofeither horizontally scaled groups of resources or partitioned resources Type: String Default: '01' pMonitoringTopicArn: Description: Monitoring Topic Arn Type: String pTargetGroupFullName: Description: The TargetGroup Arn Type: String Conditions: EnableCloudWatchAlarm: !Equals [ !Ref pCloudWatchAlarmFlag, 'true' ] Resources: #See AWS Resource Naming Standards - https://exampleent.atlassian.net/wiki/spaces/CLOUDDOC/pages/149718262/ELZ+AWS+Resource+Naming+Standards#ELZAWSResourceNamingStandards-CloudWatch #Create a cloudwatch alarm for http5xxx status codes generated by the target group #when the number generated exceeds 1 in a 300 second period. #See https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cw-alarm.html rEcsFargateHTTPCodeTarget5XXTooHighAlarm: Type: 'AWS::CloudWatch::Alarm' Properties: AlarmDescription: 'Application load balancer receives 5XX HTTP status codes from EcsFargate' AlarmName: !Sub '${pApp}-HTTPCodeTarget5XXTooHighAlarm' Namespace: 'AWS/ApplicationELB' MetricName: HTTPCode_Target_5XX_Count Statistic: Sum Period: 300 EvaluationPeriods: 1 ComparisonOperator: GreaterThanThreshold Threshold: 1 AlarmActions: !If - EnableCloudWatchAlarm - - Ref: pMonitoringTopicArn # - Ref: pServiceNowTopicArn - !Ref AWS::NoValue Dimensions: - Name: TargetGroup Value: !Ref pTargetGroupFullName #Create alarm when number of unhealthy hosts exceeds one in a 300 second period. #See https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cw-alarm.html rEcsFargateTargetConnectionErrorCountTooHighAlarm: Type: 'AWS::CloudWatch::Alarm' Properties: AlarmDescription: 'Application load balancer receives 5XX HTTP status codes from EcsFargate' Namespace: 'AWS/ApplicationELB' MetricName: UnHealthyHostCount AlarmName: !Sub '${pApp}-EcsFargateTargetConnectionErrorCountTooHighAlarm' Statistic: Sum Period: 300 EvaluationPeriods: 1 ComparisonOperator: GreaterThanThreshold Threshold: 1 AlarmActions: !If - EnableCloudWatchAlarm - - Ref: pMonitoringTopicArn # - Ref: pServiceNowTopicArn - !Ref AWS::NoValue Dimensions: - Name: TargetGroup Value: !Ref pTargetGroupFullName #Create a cloudwatch alarm if CPU Utilization is greater than 80% in a 300 second period. #See https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cw-alarm.html rEcsFargateCPUUtlizationTooHighAlarm: Type: 'AWS::CloudWatch::Alarm' Properties: AlarmDescription: 'This is alarm triggered when more than 80% of CPU is utilized - EcsFargate' Namespace: 'AWS/ECS' MetricName: CPUUtilization AlarmName: !Sub '${pApp}-EcsFargateCPUUtlizationTooHighAlarm' Statistic: Sum Period: 300 EvaluationPeriods: 1 ComparisonOperator: GreaterThanThreshold Threshold: 80 Dimensions: - Name: ClusterName Value: !Ref pClusterName - Name: ServiceName Value: !Ref pFargateServiceName AlarmActions: !If - EnableCloudWatchAlarm - - Ref: pMonitoringTopicArn # - Ref: pServiceNowTopicArn - !Ref AWS::NoValue #Create a cloudwatch alarm if Memory Utilization is greater than 80% in a 300 second period. #See https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cw-alarm.html rEcsFargateMemoryUtlizationTooHighAlarm: Type: 'AWS::CloudWatch::Alarm' Properties: AlarmDescription: 'This is alarm triggered when more than 80% of Memory is utilized - EcsFargate' Namespace: 'AWS/ECS' MetricName: MemoryUtilization AlarmName: !Sub '${pApp}-EcsFargateMemoryUtlizationTooHighAlarm' Statistic: Sum Period: 300 EvaluationPeriods: 1 ComparisonOperator: GreaterThanThreshold Threshold: 80 Dimensions: - Name: ClusterName Value: !Ref pClusterName - Name: ServiceName Value: !Ref pFargateServiceName AlarmActions: !If - EnableCloudWatchAlarm - - Ref: pMonitoringTopicArn # - Ref: pServiceNowTopicArn - !Ref AWS::NoValue