Skip to main content
Module Server 0.15.13Last updated in version 0.15.4

Attach ENI Scripts

View SourceRelease Notes

This folder contains scripts you can use to attach Elastic Network Interfaces (ENIs) to your EC2 Instances.

  1. attach-eni: This script can be run on an EC2 instance to attach an ENI. You can specify the ENI by ID or by having the script search for the ENI by tag. Normally, you would use Terraform's aws_network_interface_attachment resource to do this, but this resource does not work in cases where you need to attach volumes dynamically, such as with Auto Scaling Groups.

    The script has been tested with Ubuntu 18.04, Ubuntu 20.04, AmazonLinux v1.x, and AmazonLinux v2.x, though it may work on other Linux distributions as well.

An ENI allows you to have IP addresses that remain static, even if the underlying EC2 Instances are changing.

Check out the attach-eni example for how to use these scripts with Terraform.

Installing the attach-eni script

You can install the attach-eni script using the Gruntwork Installer:

gruntwork-install --module-name "attach-eni" --repo "" --tag "0.1.10"

Using the attach-eni script

The attach-eni script has the following prerequisites:

  1. It must be run as root
  2. It must be run on an EC2 instance
  3. The EC2 instance must have an IAM role with permissions to search ENIs and EC2 tags, as well as attach ENIs (see the attach-eni example)
  4. The EC2 instance must have the AWS CLI and jq installed

Typically, you'll want to run the attach-eni script in the User Data of your EC2 instances so it attaches the ENI at boot time.

Here is an example usage:

attach-eni --eni-id eni-abcd1234

This will attach ENI eni-abcd1234 to the current Instance. Alternatively, you can also run the script as follows:

attach-eni --eni-with-same-tag Name

This tells the script to try find and attach an ENI with the same Name tag as the current EC2 Instance.