CloudWatch event target for AWS Health events

Hi Folks,

I’m trying to set up a cloudwatch event target for AWS Health events. The sample AWS health event is the following

{
  "version": "0",
  "id": "7bf73129-1428-4cd3-a780-95db273d1602",
  "detail-type": "AWS Health Event",
  "source": "aws.health",
  "account": "123456789012",
  "time": "2016-06-05T06:27:57Z",
  "region": "region",
  "resources": [],
  "detail": {
    "eventArn": "arn:aws:health:region::event/id",
    "service": "service",
    "eventTypeCode": "AWS_service_code",
    "eventTypeCategory": "category",
    "startTime": "Sun, 05 Jun 2016 05:01:10 GMT",
    "endTime": "Sun, 05 Jun 2016 05:30:57 GMT",
    "eventDescription": [{
      "language": "lang-code",
      "latestDescription": "description"
    }]
    ...
  }
}

and the Terraform code is

resource "aws_cloudwatch_event_target" "aws_health" {
  rule      = aws_cloudwatch_event_rule.aws_health.name
  target_id = "send-to-sns"
  arn       = aws_sns_topic.alerts.arn
  input_transformer {
    input_paths = {
      type        = "$.detail-type"
      account     = "$.account"
      description = "$.detail.0.eventDescription.latestDescription"
    }

    input_template = "\"You have a <type> notification in account ID <account>.  The description of the notification is as follows: <description>.\""
  }
}

My issue is that I’m not sure how to reference the input path for the event description as it is an array not a hash.

My guess is that it would be

description = "$.detail.0.eventDescription.latestDescription"

but I’m not sure as I can’t find any documentation related to this which explains the syntax when the JSON is an array.

Any ideas?

Thanks in advance for any pointers.

Trevor

I struggled with this for a while , the correct syntax is to pick the array you want to access (I am assuming this is the logic ) and the value you want from that array.

“$.detail.eventDescription.0.latestDescription”

I honestly only found this through trial and error using the generate output ability in the transformer.

“$.detail.eventDescription.0.language” would print the eventDescription array value or language.

Hope this helps

Wow…that was a blast from the past! I’d almost forgotten I’d even asked this question.

Thanks for sharing your solution. It’s always annoying to see a question with no answer.

Thanks,
Trevor

Updating this for posterity. The correct answer is:-

resource "aws_cloudwatch_event_target" "aws_health" {
  rule      = aws_cloudwatch_event_rule.aws_health.name
  target_id = "send-to-sns"
  arn       = aws_sns_topic.alerts.arn
  input_transformer {
    input_paths = {
      type        = "$.detail-type"
      account     = "$.account"
      description = "$.detail.eventDescription[0].latestDescription"
    }

    input_template = "\"You have a <type> notification in account ID <account>.  The description of the notification is as follows: <description>.\""
  }
}