VM::EC2::NetworkInterface(3) Object describing an Amazon Elastic Network Interface (ENI)


use VM::EC2;
my $ec2 = VM::EC2->new(...);
my $interface = $ec2->describe_network_interfaces('eni-12345');
print $interface->subNetId,"\n",


This object provides access to information about Amazon Elastic Network Interface objects, which are used in conjunction with virtual private cloud (VPC) instances to create multi-homed web servers, routers, firewalls, and so forth.

Please see VM::EC2::Generic for methods shared by all VM::EC2 objects.


These object methods are supported:

 networkInterfaceId       -- The ID of this ENI
 subnetId                 -- The ID of the subnet this ENI belongs to
 vpcId                    -- The ID of the VPC this ENI belongs to
 ownerId                  -- Owner of the ENI
 status                   -- ENI status, one of "available" or "in-use"
 privateIpAddress         -- Primary private IP address of the ENI
 privateDnsName           -- Primary private DNS name of the ENI
                             as a set of VM::EC2::Group objects.
 attachment               -- Information about the attachment of this ENI to
                             an instance, as a VM::EC2::NetworkInterface::Attachment
 association              -- Information about the association of this ENI with
                             an elastic public IP address.
 privateIpAddresses       -- List of private IP addresses assigned to this ENI,
                             as a list of VM::EC2::NetworkInterface::PrivateIpAddress
 availabilityZone         -- Availability zone for this ENI as a VM::EC2::AvailabilityZone
 macAddress               -- MAC address for this interface.

In addition, this object supports the following convenience methods:

 resetAttributes()          -- Return attributes to their default states. Currently only
                               sets the SourceDestCheck value to true.
 description([$new_value])  -- Description of the ENI. Pass a single argument to set a new
 sourceDestCheck([$boolean])-- Boolean value. If true, prevent this ENI from
                               forwarding packets between subnets. Value can optionally
                               be set
 security_groups([@new_groups]) -- List of security groups this ENI belongs to. Pass a
                               list of new security groups to change this value.
                            -- Whether the deleteOnTermination flag is set for the current
                               attachment. Pass a boolean value to change the value.

Attaching to an instance

The following methods allow the interface to be attached to, and detached from, instances.

$attachment_id = $interface->attach($instance_id => $device)

$attachment_id = $interfacee->attach(-instance_id => $id, -device_index => $device)

This method attaches the network interface an instance using the the indicated device index. You can provide either an instance ID, or a VM::EC2::Instance object. You may use an integer for -device_index, or use the strings ``eth0'', ``eth1'' etc.

Required arguments:

 -instance_id          ID of the instance to attach to.
 -device_index         Network device number to use (e.g. 0 for eth0).

On success, this method returns the attachmentId of the new attachment (not a VM::EC2::NetworkInterface::Attachment object, due to an AWS API inconsistency).

$boolean = $interface->detach([$force])

This method detaches the network interface from whatever instance it is currently attached to. If a true argument is provided, then the detachment will be forced, even if the interface is in use.

On success, this method returns a true value.

Adding IP addresses

$result = $interface->assign_private_ip_addresses(@addresses)

$result = $interface->assign_private_ip_addresses(%args)

Assign one or more secondary private IP addresses to the network interface. You can either set the addresses explicitly, or provide a count of secondary addresses, and let Amazon select them for you.

In the list argument form, pass a list of desired IP addresses, or a count of the number of addresses to select for you:

 $interface->assign_private_ip_addresses(3);  # three automatic addresses

Required arguments:

 -private_ip_address      One or more secondary IP addresses, as a scalar string
 -private_ip_addresses    or array reference. (The two arguments are equivalent).

Optional arguments:

 -allow_reassignment      If true, allow assignment of an IP address is already in
                          use by another network interface or instance.

The following are valid arguments to -private_ip_address:

 -private_ip_address => ''                    # single address
 -private_ip_address => ['',']    # multiple addresses
 -private_ip_address => 3                                 # autoselect three addresses

The mixed form of address, such as ['','auto'] is not allowed in this call.

On success, this method returns true.

$result = $interface->unassign_private_ip_addresses(@addresses)

$result = $interface->unassign_private_ip_addresses(-private_ip_address => \@addresses)

Unassign one or more secondary private IP addresses from the network interface.

In the list argument form, pass a list of desired IP addresses to unassign.


In the named argument form, use:

 -private_ip_address      One or more secondary IP addresses, as a scalar string
 -private_ip_addresses    or array reference. (The two arguments are equivalent).

The following are valid arguments to -private_ip_address:

 -private_ip_address => ''                    # single address
 -private_ip_address => ['',']    # multiple addresses

On success, this method returns true.


When used in a string context, this object will be interpolated as the networkInterfaceId


Lincoln Stein <[email protected]>.

Copyright (c) 2012 Ontario Institute for Cancer Research

This package and its accompanying libraries is free software; you can redistribute it and/or modify it under the terms of the GPL (either version 1, or at your option, any later version) or the Artistic License 2.0. Refer to LICENSE for the full license text. In addition, please see DISCLAIMER.txt for disclaimers of warranty.