salt.modules.boto_ec2

Connection module for Amazon EC2

New in version TBD.

configuration:

This module accepts explicit EC2 credentials but can also utilize IAM roles assigned to the instance trough Instance Profiles. Dynamic credentials are then automatically obtained from AWS API and no further configuration is necessary. More Information available at:

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html

If IAM roles are not used you need to specify them either in a pillar or in the minion's config file:

ec2.keyid: GKTADJGHEIQSXMKKRBJ08H
ec2.key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs

A region may also be specified in the configuration:

ec2.region: us-east-1

If a region is not specified, the default is us-east-1.

It's also possible to specify key, keyid and region via a profile, either as a passed in dict, or as a string to pull from pillars or minion config:

myprofile:
    keyid: GKTADJGHEIQSXMKKRBJ08H
    key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs
    region: us-east-1
depends:

boto

salt.modules.boto_ec2.create_key(key_name, save_path, region=None, key=None, keyid=None, profile=None)

Creates a key and saves it to a given path. Returns the private key.

CLI Example:

salt myminion boto_ec2.create mykey /root/
salt.modules.boto_ec2.delete_key(key_name, region=None, key=None, keyid=None, profile=None)

Deletes a key. Always returns True

CLI Example:

salt myminion boto_ec2.delete_key mykey
salt.modules.boto_ec2.exists(instance_id=None, name=None, tags=None, region=None, key=None, keyid=None, profile=None)

Given a instance id, check to see if the given instance id exists.

Returns True if the given an instance with the given id, name, or tags exists; otherwise, False is returned.

CLI Example:

salt myminion boto_ec2.exists myinstance
salt.modules.boto_ec2.find_instances(instance_id=None, name=None, tags=None, region=None, key=None, keyid=None, profile=None, return_objs=False)

Given instance properties, find and return matching instance ids

CLI Examples:

salt myminion boto_ec2.find_instances # Lists all instances
salt myminion boto_ec2.find_instances name=myinstance
salt myminion boto_ec2.find_instances tags='{"mytag": "value"}'
salt.modules.boto_ec2.get_attribute(attribute, instance_name=None, instance_id=None, region=None, key=None, keyid=None, profile=None)

Get an EC2 instance attribute.

CLI Example:

salt myminion boto_ec2.get_attribute name=my_instance attribute=sourceDestCheck
Available attributes:
  • instanceType
  • kernel
  • ramdisk
  • userData
  • disableApiTermination
  • instanceInitiatedShutdownBehavior
  • rootDeviceName
  • blockDeviceMapping
  • productCodes
  • sourceDestCheck
  • groupSet
  • ebsOptimized
  • sriovNetSupport
salt.modules.boto_ec2.get_id(name=None, tags=None, region=None, key=None, keyid=None, profile=None)

Given instace properties, return the instance id if it exist.

CLI Example:

salt myminion boto_ec2.get_id myinstance
salt.modules.boto_ec2.get_key(key_name, region=None, key=None, keyid=None, profile=None)

Check to see if a key exists. Returns fingerprint and name if it does and False if it doesn't CLI Example:

salt myminion boto_ec2.get_key mykey
salt.modules.boto_ec2.get_keys(keynames=None, filters=None, region=None, key=None, keyid=None, profile=None)

Gets all keys or filters them by name and returns a list. keynames (list):: A list of the names of keypairs to retrieve. If not provided, all key pairs will be returned. filters (dict) :: Optional filters that can be used to limit the results returned. Filters are provided in the form of a dictionary consisting of filter names as the key and filter values as the value. The set of allowable filter names/values is dependent on the request being performed. Check the EC2 API guide for details.

CLI Example:

salt myminion boto_ec2.get_keys
salt.modules.boto_ec2.get_zones(region=None, key=None, keyid=None, profile=None)

Get a list of AZs for the configured region.

CLI Example:

salt myminion boto_ec2.get_zones
salt.modules.boto_ec2.import_key(key_name, public_key_material, region=None, key=None, keyid=None, profile=None)

Imports the public key from an RSA key pair that you created with a third-party tool. Supported formats: - OpenSSH public key format (e.g., the format in ~/.ssh/authorized_keys) - Base64 encoded DER format - SSH public key file format as specified in RFC4716 - DSA keys are not supported. Make sure your key generator is set up to create RSA keys. Supported lengths: 1024, 2048, and 4096.

CLI Example:

salt myminion boto_ec2.import mykey publickey
salt.modules.boto_ec2.run(image_id, name=None, tags=None, instance_type='m1.small', key_name=None, security_groups=None, user_data=None, placement=None, region=None, key=None, keyid=None, profile=None)

Create and start an EC2 instance.

Returns True if the instance was created; otherwise False.

CLI Example:

salt myminion boto_ec2.run ami-b80c2b87 name=myinstance
salt.modules.boto_ec2.set_attribute(attribute, attribute_value, instance_name=None, instance_id=None, region=None, key=None, keyid=None, profile=None)

Set an EC2 instance attribute. Returns whether the operation succeeded or not.

CLI Example:

salt myminion boto_ec2.set_attribute instance_name=my_instance                 attribute=sourceDestCheck attribute_value=False
Available attributes:
  • instanceType
  • kernel
  • ramdisk
  • userData
  • disableApiTermination
  • instanceInitiatedShutdownBehavior
  • rootDeviceName
  • blockDeviceMapping
  • productCodes
  • sourceDestCheck
  • groupSet
  • ebsOptimized
  • sriovNetSupport
salt.modules.boto_ec2.terminate(instance_id=None, name=None, region=None, key=None, keyid=None, profile=None)

Terminate the instance described by instance_id or name.

CLI Example:

salt myminion boto_ec2.terminate name=myinstance
salt myminion boto_ec2.terminate instance_id=i-a46b9f