Amazon EC2 Driver Documentation

Amazon Elastic Compute Cloud (EC2) is one of the oldest IaaS service providers out there and a central part of Amazon.com’s cloud computing platform, Amazon Web Services (AWS).

../../_images/aws.png

It allows users to rent virtual servers in more than 9 regions such as:

  • US East (Northern Virginia) Region
  • US East (Ohio) Region
  • US West (Oregon) Region
  • US West (Northern California) Region
  • EU West (Ireland) Region
  • EU Central (Frankfurt) Region
  • Asia Pacific (Singapore) Region
  • Asia Pacific (Sydney) Region
  • Asia Pacific (Tokyo) Region
  • South America (Sao Paulo) Region

Using temporary security credentials

Since Libcloud 0.14.0 above, all the Amazon drivers support using temporary security credentials.

Temporary credentials can be used by passing token argument to the driver constructor in addition to the access and secret key. In this case token represents a temporary session token, access key represents temporary access key and secret key represents a temporary secret key.

For example:

from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

cls = get_driver(Provider.EC2)
driver = cls('temporary access key', 'temporary secret key',
             token='temporary session token', region="us-west-1")

For more information, please refer to the Using Temporary Security Credentials section of the official documentation.

Examples

Allocate, Associate, Disassociate, and Release an Elastic IP

from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

ACCESS_ID = 'your access id'
SECRET_KEY = 'your secret key'

IMAGE_ID = 'ami-c8052d8d'
SIZE_ID = 't1.micro'

cls = get_driver(Provider.EC2)
driver = cls(ACCESS_ID, SECRET_KEY, region="us-west-1")

sizes = driver.list_sizes()
images = driver.list_images()

size = [s for s in sizes if s.id == SIZE_ID][0]
image = [i for i in images if i.id == IMAGE_ID][0]

node = driver.create_node(name='test-node', image=image, size=size)

# Here we allocate and associate an elastic IP
elastic_ip = driver.ex_allocate_address()
driver.ex_associate_address_with_node(node, elastic_ip)

# When we are done with our elastic IP, we can disassociate from our
# node, and release it
driver.ex_disassociate_address(elastic_ip)
driver.ex_release_address(elastic_ip)

Create a general purpose SSD volume

from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

cls = get_driver(Provider.EC2, region='us-east-i1')
driver = cls('access key', 'secret key')

volume = driver.create_volume(size=100, name='Test GP volume',
                              ex_volume_type='gp2')

Create a provisioned IOPS volume

from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

cls = get_driver(Provider.EC2, region='us-east-i1')
driver = cls('access key', 'secret key')

volume = driver.create_volume(size=100, name='Test IOPS volume',
                              ex_volume_type='io1', ex_iops=1000)

API Docs