Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Amazon EC2 Cookbook

You're reading from   Amazon EC2 Cookbook Over 40 hands-on recipes to develop and deploy real-world applications using Amazon EC2

Arrow left icon
Product type Paperback
Published in Nov 2015
Publisher Packt
ISBN-13 9781785280047
Length 194 pages
Edition 1st Edition
Arrow right icon
Toc

Table of Contents (10) Chapters Close

Preface 1. Selecting and Configuring Amazon EC2 Instances FREE CHAPTER 2. Configuring and Securing a Virtual Private Cloud 3. Managing AWS Resources Using AWS CloudFormation 4. Securing Access to Amazon EC2 Instances 5. Monitoring Amazon EC2 Instances 6. Using AWS Data Services 7. Accessing Other AWS Services 8. Deploying AWS Applications Index

Allocating Elastic IP addresses

Elastic IP (EIP) address is the static public IP address. You can attach and detach the EIP from EC2 instance at any time. Instances in EC2-Classic support only one private IP address and corresponding EIP. Instances in EC2-VPC support multiple private IP addresses, and each one can have a corresponding EIP. If you stop the instance in EC2-Classic the EIP is disassociated from instance, and you have to associate it again when you start the instance. But if you stop the instance in EC2-VPC, the EIP remains associated with the EC2 instance.

In this recipe, we list the commands for allocating an Elastic IP address in a VPC and associating it with the network interface.

How to do it…

For allocating EIP addresses, perform the following steps:

  1. Run the following command to allocate the EIP:
    $ aws ec2 allocate-address 
    --domain [Domain]
    

    You have to specify whether domain is standard or VPC. Record the allocation ID for further use.

    Domain value indicates whether the EIP address is used with instances in EC2-Classic (standard) or instances in a EC2-VPC (VPC).

  2. Next, run the following command to create the EIP in VPC:
    $ aws ec2 allocate-address --domain vpc
    
  3. Then, run the following command to associate the EIP to the Elastic Network Interface (ENI):
    $ aws ec2 associate-address 
    --network-interface-id [NetworkInterfaceId]
    --allocation-id [AllocationId]
    

    You need to provide the network interface ID of the ENI and allocation ID of the EIP you obtained in step 1. If you don't specify the private IP address, then the Elastic IP address is associated with the primary IP address.

    The parameters used in this command are described here:

    • [NetworkInterfaceId]: This gives the ENI ID to attach
    • [AllocationId]: This provides the allocation ID of the EIP for EC2-VPC
  4. Finally, run the following command to associate the EIP to ENI:
    $ aws ec2 associate-address 
    --network-interface-id eni-d68df2b3 
    --allocation-id eipalloc-82e0ffe0
    

See also

  • The Creating an instance with multiple NIC cards and a static private IP address recipe
You have been reading a chapter from
Amazon EC2 Cookbook
Published in: Nov 2015
Publisher: Packt
ISBN-13: 9781785280047
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime