ruby/example_code/ec2/ec2-ruby-example-elastic-ips.rb
def associate_elastic_ip_address_with_instance(
  ec2_client,
  allocation_id,
  instance_id
)
  response = ec2_client.associate_address(
    allocation_id: allocation_id,
    instance_id: instance_id,
  )
  return response.association_id
rescue StandardError => e
  puts "Error associating Elastic IP address with instance: #{e.message}"
  return 'Error'
end
# Associates an Elastic IP address with an Amazon Elastic Compute Cloud
# (Amazon EC2) instance.
#
# Prerequisites:
#
# - The allocation ID corresponding to the Elastic IP address.
# - The Amazon EC2 instance.
#
# @param ec2_client [Aws::EC2::Client] An initialized EC2 client.
# @param allocation_id [String] The ID of the allocation corresponding to
#   the Elastic IP address.
# @param instance_id [String] The ID of the instance.
# @return [String] The assocation ID corresponding to the association of the
#   Elastic IP address to the instance.
# @example
#   puts allocate_elastic_ip_address(
#     Aws::EC2::Client.new(region: 'us-west-2'),
#     'eipalloc-04452e528a66279EX',
#     'i-033c48ef067af3dEX')

Associates an Elastic IP address with an Amazon Elastic Compute Cloud
(Amazon EC2) instance.



The allocation ID corresponding to the Elastic IP address.
The Amazon EC2 instance.
Associates an Elastic IP address with an Amazon Elastic Compute Cloud ( Amazon EC2 ) instance . The allocation ID corresponding to the Elastic IP address . The Amazon EC2 instance .
def associate_elastic_ip_address_with_instance(
  ec2_client,
  allocation_id,
  instance_id
)
  response = ec2_client.associate_address(
    allocation_id: allocation_id,
    instance_id: instance_id,
  )
  return response.association_id
rescue StandardError => e
  puts "Error associating Elastic IP address with instance: #{e.message}"
  return 'Error'
end
def associate_elastic_ip_address_with_instance ( ec2_client , allocation_id , instance_id ) response = ec2_client . associate_address ( allocation_id : allocation_id , instance_id : instance_id , ) return response . association_id rescue StandardError => e puts "Error associating Elastic IP address with instance: #{e.message}" return 'Error' end
Associates an Elastic IP address with an Amazon Elastic Compute Cloud
(Amazon EC2) instance.
Associates an Elastic IP address with an Amazon Elastic Compute Cloud ( Amazon EC2 ) instance .
The assocation ID corresponding to the association of the Elastic IP address to the instance.
The assocation ID corresponding to the association of the Elastic IP address to the instance .
String
ec2_client
An initialized EC2 client.
An initialized EC2 client .
allocation_id
The ID of the allocation corresponding to the Elastic IP address.
The ID of the allocation corresponding to the Elastic IP address .
instance_id
The ID of the instance.
The ID of the instance .
example
None