Boto2

Boto2 is a common library used in the AWS world, and thus is compatible with OUTSCALE APIs. This page presents how to start with the library with basic examples, and you may find further examples within this technical guide.

Linux and Windows Configuration

If you already have python installed on your platform, Boto2 is a python library available through the pip utility:

$ pip install boto

Boto2 is compatible with python2 and python3, though it is recommended to use python2.

Examples

Initialization

To initialize your connector on OUTSCALE endpoint, use the following commands:

from boto.ec2.regioninfo import EC2RegionInfo
from boto.vpc import VPCConnection

your_ak, your_sk = "XXXXXAAAXXXXXX", "ZZZZZZBBBBBBZZZZZZBBBBBBBZZZZZZZ"
outscale_endpoint = EC2RegionInfo(endpoint="fcu.eu-west-2.outscale.com")    # you can change the region
outscale_fcu = VPCConnection( aws_access_key_id = your_ak, aws_secret_access_key = your_sk, region = outscale_endpoint)

You need to get your AK and your SK from Cockpit to allow a connection to the API. For more information, see Getting Information About Your Access Keys.

Scripts

Now that your connector is ready, you can check if it works and list all available regions, using the following command:

Request sample
>>> outscale_fcu.get_all_regions()

This command should return:

Result sample
[RegionInfo:eu-west-2, RegionInfo:us-east-2, RegionInfo:us-west-1]

VPC

Now, you can create a simple VPC and a subnet, using the following commands:

>>> new_vpc = outscale_fcu.create_vpc(cidr_block = "10.0.0.0/16")
>>> new_subnet = outscale_fcu.create_subnet(vpc_id = new_vpc.id, cidr_block = "10.0.10.0/24", availability_zone = "eu-west-2a")

The VPC and the subnet are created. You can now create security groups, instances and routing inside your VPC.

Block Device Mapping

When creating an instance you can add specific volumes depending on the type of your instance. For more information, see Working with Volumes and Defining Block Device Mappings.

Here is an example to create a instance with an ephemeral and an io1 volume attached to the instance. The io1 volume is expected to provide 10k IOPS.

from boto.ec2.blockdevicemapping import BlockDeviceType, BlockDeviceMapping
# Prepare block device mapping
mapping = BlockDeviceMapping()
mapping['/dev/xvdb'] = BlockDeviceType(ephemeral_name='ephemeral0')
mapping['/dev/xvdc'] = BlockDeviceType(volume_type='io1', iops=10000, size=400, delete_on_termination=True)
instance = ows.run_instances(image_id='ami-xxxxxx', key_name='my_keypair', block_device_map=mapping, instance_type='i2.xlarge')

Related Pages

AWS™ and Amazon Web Services™ are trademarks of Amazon Technologies, Inc or its affiliates in the United States and/or other countries.