ruby/example_code/ec2/ec2-ruby-example-elastic-ips.rb
# Checks whether the specified Amazon Elastic Compute Cloud
# (Amazon EC2) instance exists.
#
# 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 exists; otherwise, false.
# @example
#   exit 1 unless instance_exists?(
#     Aws::EC2::Client.new(region: 'us-west-2'),
#     'i-033c48ef067af3dEX'
#   )

Checks whether the specified Amazon Elastic Compute Cloud
(Amazon EC2) instance exists.



The Amazon EC2 instance.
Checks whether the specified Amazon Elastic Compute Cloud ( Amazon EC2 ) instance exists . The Amazon EC2 instance .
def instance_exists?(ec2_client, instance_id)
  ec2_client.describe_instances(instance_ids: [instance_id])
  return true
rescue StandardError
  return false
end
def instance_exists? ( ec2_client , instance_id ) ec2_client . describe_instances ( instance_ids : [ instance_id ] ) return true rescue StandardError return false end
Checks whether the specified Amazon Elastic Compute Cloud
(Amazon EC2) instance exists.
Checks whether the specified Amazon Elastic Compute Cloud ( Amazon EC2 ) instance exists .
true if the instance exists; otherwise, false.
true if the instance exists ; 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
None