AWS cloudformation Healthcheck не может ассоциироваться с Alarm - PullRequest
0 голосов
/ 31 марта 2020

Я пытаюсь создать базовый c Healthcheck для IP на http. Если эта проверка работоспособности завершается неудачно, срабатывает сигнал тревоги, который в свою очередь отправляет SNS topi c на подписку электронной почты. Кажется, все создано, но на вкладке ALARMS в конфигурации Healthcheck ничего не отображается ...

Я запускаю это на us-east-1

Может кто-нибудь помочь мне Видишь, что я делаю не так?

AWSTemplateFormatVersion: '2010-09-09'

# Should be created as [StackName]-nodes so that all exports are specified to be part of the RDS stack. 
#
# i.e. phoenix-telco-proxy-functions
#

Description: Datacenter Healthchecks

Parameters:

  AWSRegion:
    Description: Region where the Healthchecks will be created 
    Type: String
    Default: us-east-1
    AllowedValues:
      - eu-west-1
      - eu-west-2
      - eu-west-3
      - us-east-1

  HealthcheckName:
    Type: String
    Description: Name of the healthcheck to create

  AlarmName:
    Type: String
    Description: Name of the alarm to create

ProdIPAddress:
    Type: String
    Description: IPAddress to monitor

  TagsProduct:
    Type: String
    Description: Product Name (initiative based)

  TagsComponent:
    Type: String
    Description: Component Name (service based)
    Default: HeathCheck

  TagsEnv:
    Type: String
    Description: Environment (dev, qa, canary, prod, other...)
    Default: prod
    AllowedValues:
      - prod
      - dev
      - staging

  TagsOwner:
    Type: String
    Description: Product Owner (Team or Individual)

  TagsContact:
    Type: String
    Description: Technical Contact (Team or Individual)

  Email1:
    Type: String
    Description: Email address to notify when an alarm is triggered

Resources:

  NotifyMe:
    Type: AWS::SNS::Topic
    Properties:
      Subscription:
      - Endpoint:
          Ref: Email1 
        Protocol: email

ProdHealthcheck:
    Type: AWS::Route53::HealthCheck
    Properties: 
      HealthCheckConfig: 
        FailureThreshold: 2
        ResourcePath: "/alive.html"
        IPAddress: !Ref IPAddress
        Inverted: false
        Port: 80
        RequestInterval: 30
        Type: HTTP
        Regions:
          - eu-west-1
          - sa-east-1
          - us-east-1
      HealthCheckTags: 
        - Key: Owner
          Value: !Ref TagsOwner
        - Key: Contact
          Value: !Ref TagsContact
        - Key: Product
          Value: !Ref TagsProduct
        - Key: Env
          Value: !Ref TagsEnv
        - Key: TagsComponent
          Value: !Ref TagsComponent
        - Key: Name 
          Value: !Ref AlarmName


  ProdAlarmFailure:
    Type: AWS::CloudWatch::Alarm
    Properties: 
      ActionsEnabled: true
      AlarmActions: 
        - !Ref NotifyMe
      InsufficientDataActions: 
        - !Ref NotifyMe
      OKActions: 
        - !Ref NotifyMe
      AlarmDescription: !Ref AlarmName
      AlarmName: HealthCheckStatus
      ComparisonOperator: LessThanThreshold
      Threshold: 1
      Period: 60
      DatapointsToAlarm: 2
      EvaluationPeriods: 2
      Dimensions: 
        - Name: HealthCheckId
          Value: !Ref ProdHealthcheck
      MetricName: HealthCheckStatus
      Namespace: AWS/Route53
      Statistic: Maximum
      TreatMissingData: breaching

РЕДАКТИРОВАТЬ:

Я смог создать все это только с помощью terrafrom следующим образом:

# Configure the AWS Provider
provider "aws" {
    alias = "use1"
    version = "~> 2.0"
}

######### Variables ##########

variable "aws_region" {
    type = string
    default = "us-east-1"
}

variable "healthcheck_name" {
    type = string
}

variable "hc_regions" {
    type    = list(string)
    default = [ "eu-west-1", "sa-east-1", "us-east-1" ]
}

variable "ip_address" {
    type = string
}

variable "resource_path" {
    type = string
}

variable "resource_port" {
    type = string
}

variable "email_addresses_1" {
    type        = string
    description = "Email address to send notifications to"
    default = "email1"
}

variable "email_addresses_2" {
    type        = string
    description = "Email address to send notifications to"
    default = "email2"
}

######### SNS Topic and Subscription ##########

resource "aws_sns_topic" "email_notifications" {
    name = var.healthcheck_name

    provisioner "local-exec" {
        command = "AWS_DEFAULT_REGION='${var.aws_region}' aws sns subscribe --topic-arn ${self.arn} --protocol email --notification-endpoint ${var.email_addresses_1}"
    }

    provisioner "local-exec" {
        command = "AWS_DEFAULT_REGION='${var.aws_region}' aws sns subscribe --topic-arn ${self.arn} --protocol email --notification-endpoint ${var.email_addresses_2}"
    }
}

######### Route53 HealthCheck ##########

resource "aws_route53_health_check" "prod-hc" {
    provider                = aws.use1
    ip_address              = var.ip_address
    type                    = "HTTP"
    resource_path           = var.resource_path
    port                    = var.resource_port
    failure_threshold       = "2"
    request_interval        = "30"
    regions                 = var.hc_regions

    tags = {
        Product         = "Voice Servers Monitoring"
        Owner           = "mp-devops"
        TagsComponent   = "HeathCheck"
        Env             = "prod"
        Contact         = "mp-david"
        Name            = var.healthcheck_name
    }
}

######### Cloudwatch Alarm ##########

resource "aws_cloudwatch_metric_alarm" "prod-alarm" {
  alarm_name          = var.healthcheck_name
  comparison_operator = "LessThanThreshold"
  evaluation_periods  = "2"
  metric_name         = "HealthCheckStatus"
  namespace           = "AWS/Route53"
  statistic           = "Maximum"
  threshold           = "1"
  period              = "60"
  alarm_actions       = [ aws_sns_topic.email_notifications.arn ]
  ok_actions          = [ aws_sns_topic.email_notifications.arn ]
  alarm_description   = "Prod Monitoring"

  dimensions          = {
    HealthCheckId = aws_route53_health_check.prod-hc.id
  }
}

Мне пришлось фактически установить регион вручную при применении планируйте в terraform так:

AWS_DEFAULT_REGION="us-east-1" terraform apply CreateAlarm.plan

Хотя я я работаю над AWS 'us-east-1 Console ... Это должно быть что-то глупое ...

1 Ответ

0 голосов
/ 21 апреля 2020

Я использовал terraform для этого.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...