ruby/example_code/ec2/ec2-ruby-example-regions-availability-zones.rb
def list_availability_zones(ec2_client)
  result = ec2_client.describe_availability_zones
  # Enable pretty printing.
  max_region_string_length = 16
  max_zone_string_length = 18
  max_state_string_length = 9
  # Print header.
  print 'Region'
  print ' ' * (max_region_string_length - 'Region'.length)
  print '  Zone'
  print ' ' * (max_zone_string_length - 'Zone'.length)
  print "  State\n"
  print '-' * max_region_string_length
  print '  '
  print '-' * max_zone_string_length
  print '  '
  print '-' * max_state_string_length
  print "\n"
  # Print Regions, Availability Zones, and their states.
  result.availability_zones.each do |zone|
    print zone.region_name
    print ' ' * (max_region_string_length - zone.region_name.length)
    print '  '
    print zone.zone_name
    print ' ' * (max_zone_string_length - zone.zone_name.length)
    print '  '
    print zone.state
    # Print any messages for this Availability Zone.
    if zone.messages.count.positive?
      print "\n"
      puts '  Messages for this zone:'
      zone.messages.each do |message|
        print "    #{message.message}\n"
      end
    end
    print "\n"
  end
end
# Displays a list of Amazon Elastic Compute Cloud (Amazon EC2)
# Availability Zones available to you depending on the AWS Region
# of the Amazon EC2 client.
#
# @param ec2_client [Aws::EC2::Client] An initialized EC2 client.
# @example
#   list_availability_zones(Aws::EC2::Client.new(region: 'us-west-2'))

Displays a list of Amazon Elastic Compute Cloud (Amazon EC2)
Availability Zones available to you depending on the AWS Region
of the Amazon EC2 client.
Displays a list of Amazon Elastic Compute Cloud ( Amazon EC2 ) Availability Zones available to you depending on the AWS Region of the Amazon EC2 client .
def list_availability_zones(ec2_client)
  result = ec2_client.describe_availability_zones
  max_region_string_length = 16
  max_zone_string_length = 18
  max_state_string_length = 9
  print 'Region'
  print ' ' * (max_region_string_length - 'Region'.length)
  print '  Zone'
  print ' ' * (max_zone_string_length - 'Zone'.length)
  print "  State\n"
  print '-' * max_region_string_length
  print '  '
  print '-' * max_zone_string_length
  print '  '
  print '-' * max_state_string_length
  print "\n"
  result.availability_zones.each do |zone|
    print zone.region_name
    print ' ' * (max_region_string_length - zone.region_name.length)
    print '  '
    print zone.zone_name
    print ' ' * (max_zone_string_length - zone.zone_name.length)
    print '  '
    print zone.state
    if zone.messages.count.positive?
      print "\n"
      puts '  Messages for this zone:'
      zone.messages.each do |message|
        print "    #{message.message}\n"
      end
    end
    print "\n"
  end
end
def list_availability_zones ( ec2_client ) result = ec2_client . describe_availability_zones max_region_string_length = 16 max_zone_string_length = 18 max_state_string_length = 9 print 'Region' print ' ' * ( max_region_string_length - 'Region' . length ) print '  Zone' print ' ' * ( max_zone_string_length - 'Zone' . length ) print "  State\n" print '-' * max_region_string_length print '  ' print '-' * max_zone_string_length print '  ' print '-' * max_state_string_length print "\n" result . availability_zones . each do | zone | print zone . region_name print ' ' * ( max_region_string_length - zone . region_name . length ) print '  ' print zone . zone_name print ' ' * ( max_zone_string_length - zone . zone_name . length ) print '  ' print zone . state if zone . messages . count . positive? print "\n" puts '  Messages for this zone:' zone . messages . each do | message | print "    #{message.message}\n" end end print "\n" end end
Displays a list of Amazon Elastic Compute Cloud (Amazon EC2)
Availability Zones available to you depending on the AWS Region
of the Amazon EC2 client.
Displays a list of Amazon Elastic Compute Cloud ( Amazon EC2 ) Availability Zones available to you depending on the AWS Region of the Amazon EC2 client .
# Enable pretty printing.
 # Print header.
 # Print Regions, Availability Zones, and their states.
 # Print any messages for this Availability Zone.

ec2_client
An initialized EC2 client.
An initialized EC2 client .
example
None