ruby/example_code/cloudwatch/cw-ruby-example-alarm-basics.rb
def list_alarms(cloudwatch_client)
  response = cloudwatch_client.describe_alarms
  if response.metric_alarms.count.positive?
    response.metric_alarms.each do |alarm|
      puts alarm.alarm_name
    end
  else
    puts 'No alarms found.'
  end
rescue StandardError => e
  puts "Error getting information about alarms: #{e.message}"
end
# Lists the names of available Amazon CloudWatch alarms.
#
# @param cloudwatch_client [Aws::CloudWatch::Client]
#   An initialized CloudWatch client.
# @example
#   list_alarms(Aws::CloudWatch::Client.new(region: 'us-east-1'))
Lists the names of available Amazon CloudWatch alarms.
Lists the names of available Amazon CloudWatch alarms .
def list_alarms(cloudwatch_client)
  response = cloudwatch_client.describe_alarms
  if response.metric_alarms.count.positive?
    response.metric_alarms.each do |alarm|
      puts alarm.alarm_name
    end
  else
    puts 'No alarms found.'
  end
rescue StandardError => e
  puts "Error getting information about alarms: #{e.message}"
end
def list_alarms ( cloudwatch_client ) response = cloudwatch_client . describe_alarms if response . metric_alarms . count . positive? response . metric_alarms . each do | alarm | puts alarm . alarm_name end else puts 'No alarms found.' end rescue StandardError => e puts "Error getting information about alarms: #{e.message}" end
Lists the names of available Amazon CloudWatch alarms.
Lists the names of available Amazon CloudWatch alarms .
cloudwatch_client
An initialized CloudWatch client.
An initialized CloudWatch client .
example
None