0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【自分用】cloudformationテンプレートで条件分岐

Posted at

CloudWatchAlarmでlinuxとwindowsでMetricMathの計算方法が異なるため条件分岐させる方法
'''
Parameters:
PlatformType:
Type: String
AllowedValues:
- Linux
- Windows
Default: Linux
Description: "The platform type (Linux or Windows)"

Resources:
PlatformSpecificAlarm:
Type: "AWS::CloudWatch::Alarm"
Properties:
AlarmName: "Platform-Specific-Replica-Ratio-Alarm"
AlarmDescription: "Triggers when the replica ratio falls below threshold, based on the platform type."
Metrics:
# Linux用メトリクス
- !If
- IsLinux
- Id: replicasReadyLinux
MetricStat:
Metric:
Namespace: "Kubernetes/ContainerInsights"
MetricName: "replicas_ready"
Dimensions:
- Name: ClusterName
Value: !Ref EKSClusterName
- Name: Namespace
Value: "my-namespace"
Period: 60
Stat: "Average"
ReturnData: false
# Windows用メトリクス
- !If
- IsWindows
- Id: replicasReadyWindows
MetricStat:
Metric:
Namespace: "AWS/Windows"
MetricName: "windows_replica_ready"
Dimensions:
- Name: ClusterName
Value: !Ref EKSClusterName
- Name: Namespace
Value: "my-namespace"
Period: 60
Stat: "Average"
ReturnData: false

    - Id: replicasDesired
      MetricStat:
        Metric:
          Namespace: "Kubernetes/ContainerInsights"
          MetricName: "replicas_desired"
          Dimensions:
            - Name: ClusterName
              Value: !Ref EKSClusterName
            - Name: Namespace
              Value: "my-namespace"
          Period: 60
        Stat: "Average"
      ReturnData: false
    - Id: replicaRatio
      Expression: "replicasReady / replicasDesired * 100"
      Label: "Replica Ratio (%)"
      ReturnData: true
  EvaluationPeriods: 1
  Threshold: 90
  ComparisonOperator: "LessThanThreshold"
  TreatMissingData: "breaching"

Conditions:
IsLinux: !Equals [ !Ref PlatformType, "Linux" ]
IsWindows: !Equals [ !Ref PlatformType, "Windows" ]
'''

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?