Method: AWS::EC2::Instance#associate_elastic_ip

Defined in:
lib/aws/ec2/instance.rb

#associate_elastic_ip(elastic_ip) ⇒ nil #associate_elastic_ip(allocation_id) ⇒ nil Also known as: ip_address=

Associates the elastic IP address with this instance.

Overloads:

  • #associate_elastic_ip(elastic_ip) ⇒ nil

    Parameters:

    • elastic_ip (ElasticIp, String)

      An Elastic ip address (VPC or non-VPC) or a public ip address string (non-VPC only).

  • #associate_elastic_ip(allocation_id) ⇒ nil

    Parameters:

    • allocation_id (String)

      The allocation id of a VPC elastic ip address.

Returns:

  • (nil)


596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
# File 'lib/aws/ec2/instance.rb', line 596

def associate_elastic_ip elastic_ip

  client_opts = {}
  client_opts[:instance_id] = self.id

  if vpc?
    client_opts[:allocation_id] = elastic_ip.is_a?(ElasticIp) ?
      elastic_ip.allocation_id :
      elastic_ip.to_s
  else
    client_opts[:public_ip] = elastic_ip.to_s
  end

  client.associate_address(client_opts)
  nil

end