ruby/example_code/ec2/ec2-ruby-example-manage-instances.rb
def instance_restarted?(ec2_client, instance_id)
  ec2_client.start_instances(instance_ids: [instance_id])
  wait_for_instance(ec2_client, :instance_running, instance_id)
  return true
rescue StandardError => e
  puts "Error restarting instance: #{e.message}"
  return false
end
# Attempts to restart an Amazon Elastic Compute Cloud (Amazon EC2) instance.
#
# Prerequisites:
#
# - The Amazon EC2 instance.
#
# @param ec2_client [Aws::EC2::Client] An initialized EC2 client.
# @param instance_id [String] The ID of the instance.
# @return [Boolean] true if the instance was restarted; otherwise, false.
# @example
#   exit 1 unless instance_restarted?(
#     Aws::EC2::Client.new(region: 'us-west-2'),
#     'i-033c48ef067af3dEX'
#   )

Attempts to restart an Amazon Elastic Compute Cloud (Amazon EC2) instance.
Prerequisites.

The Amazon EC2 instance.
Attempts to restart an Amazon Elastic Compute Cloud ( Amazon EC2 ) instance . Prerequisites . The Amazon EC2 instance .
def instance_restarted?(ec2_client, instance_id)
  ec2_client.start_instances(instance_ids: [instance_id])
  wait_for_instance(ec2_client, :instance_running, instance_id)
  return true
rescue StandardError => e
  puts "Error restarting instance: #{e.message}"
  return false
end
def instance_restarted? ( ec2_client , instance_id ) ec2_client . start_instances ( instance_ids : [ instance_id ] ) wait_for_instance ( ec2_client , :instance_running , instance_id ) return true rescue StandardError => e puts "Error restarting instance: #{e.message}" return false end
Attempts to restart an Amazon Elastic Compute Cloud (Amazon EC2) instance.
Attempts to restart an Amazon Elastic Compute Cloud ( Amazon EC2 ) instance .
true if the instance was restarted; otherwise, false.
true if the instance was restarted ; otherwise false .
Boolean
ec2_client
An initialized EC2 client.
An initialized EC2 client .
instance_id
The ID of the instance.
The ID of the instance .
example
exit 1 unless instance_restarted?( Aws::EC2::Client.new(region: 'us-west-2'), 'i-033c48ef067af3dEX' )
exit 1 unless instance_restarted? ( Aws :: EC2 :: Client . new ( region : ' us - west - 2 ' ) ' i - 033c48ef067af3dEX ' )