ruby/example_code/ec2/ec2-ruby-example-manage-instances.rb
# Waits for an Amazon Elastic Compute Cloud (Amazon EC2) instance
# to reach the specified state.
#
# Prerequisites:
#
# - The Amazon EC2 instance.
#
# @param ec2_client [Aws::EC2::Client] An initialized EC2 client.
# @param instance_state [Symbol] The desired instance state.
# @param instance_id [String] The ID of the instance.
# @example
#   wait_for_instance(
#     Aws::EC2::Client.new(region: 'us-west-2'),
#     :instance_stopped,
#     'i-033c48ef067af3dEX'
#   )

Waits for an Amazon Elastic Compute Cloud (Amazon EC2) instance
to reach the specified state.



The Amazon EC2 instance.
Waits for an Amazon Elastic Compute Cloud ( Amazon EC2 ) instance to reach the specified state . The Amazon EC2 instance .
def wait_for_instance(ec2_client, instance_state, instance_id)
  ec2_client.wait_until(instance_state, instance_ids: [instance_id])
  puts "Success: #{instance_state}."
rescue Aws::Waiters::Errors::WaiterFailed => e
  puts "Failed: #{e.message}"
end
def wait_for_instance ( ec2_client , instance_state , instance_id ) ec2_client . wait_until ( instance_state , instance_ids : [ instance_id ] ) puts "Success: #{instance_state}." rescue Aws :: Waiters :: Errors :: WaiterFailed => e puts "Failed: #{e.message}" end
Waits for an Amazon Elastic Compute Cloud (Amazon EC2) instance
to reach the specified state.
Waits for an Amazon Elastic Compute Cloud ( Amazon EC2 ) instance to reach the specified state .
ec2_client
An initialized EC2 client.
An initialized EC2 client .
instance_state
The desired instance state.
The desired instance state .
instance_id
The ID of the instance.
The ID of the instance .
example
wait_for_instance( Aws::EC2::Client.new(region: 'us-west-2'), :instance_stopped, 'i-033c48ef067af3dEX' )
wait_for_instance ( Aws :: EC2 :: Client . new ( region : ' us - west - 2 ' ) : instance_stopped ' i - 033c48ef067af3dEX ' )