Class | RightAws::AsInterface |
In: |
lib/as/right_as_interface.rb
|
Parent: | RightAwsBase |
The RightAws::AsInterface class provides a complete interface to Amazon Auto Scaling service.
For explanations of the semantics of each call, please refer to Amazon‘s documentation at docs.amazonwebservices.com/AutoScaling/latest/DeveloperGuide/
Create an interface handle:
as = RightAws::AsInterface.new(aws_access_key_id, aws_security_access_key)
Create a launch configuration:
as.create_launch_configuration('CentOS.5.1-c', 'ami-08f41161', 'm1.small', :key_name => 'kd-moo-test', :security_groups => ['default'], :user_data => "Woohoo: CentOS.5.1-c" )
Create an AutoScaling group:
as.create_auto_scaling_group('CentOS.5.1-c-array', 'CentOS.5.1-c', 'us-east-1c', :min_size => 2, :max_size => 5)
Create a new trigger:
as.create_or_update_scaling_trigger('kd.tr.1', 'CentOS.5.1-c-array', :measure_name => 'CPUUtilization', :statistic => :average, :dimensions => { 'AutoScalingGroupName' => 'CentOS.5.1-c-array', 'Namespace' => 'AWS', 'Service' => 'EC2' }, :period => 60, :lower_threshold => 5, :lower_breach_scale_increment => -1, :upper_threshold => 60, :upper_breach_scale_increment => 1, :breach_duration => 300 )
Describe scaling activity:
as.incrementally_describe_scaling_activities('CentOS.5.1-c-array') #=> List of activities
Describe the Auto Scaling group status:
as.describe_auto_scaling_groups('CentOS.5.1-c-array') #=> Current group status
API_VERSION | = | '2009-05-15' | Amazon AS API version being used | |
DEFAULT_HOST | = | 'autoscaling.amazonaws.com' | ||
DEFAULT_PATH | = | '/' | ||
DEFAULT_PROTOCOL | = | 'https' | ||
DEFAULT_PORT | = | 443 |
Create a new handle to an CSLS account. All handles share the same per process or per thread HTTP connection to Amazon CSLS. Each handle is for a specific account. The params have the following options:
Creates a new auto scaling group with the specified name. Returns true or raises an exception.
Options: +:min_size+, +:max_size+, +:cooldown+, +:load_balancer_names+
as.create_auto_scaling_group('CentOS.5.1-c-array', 'CentOS.5.1-c', 'us-east-1c', :min_size => 2, :max_size => 5) #=> true
Amazon‘s notice: Constraints: Restricted to one Availability Zone
Creates a new Launch Configuration. Please note that the launch configuration name used must be unique, within the scope of your Amazon Web Services AWS account, and the maximum limit of launch configurations must not yet have been met, or else the call will fail.
Once created, the new launch configuration is available for immediate use.
Options: +:security_groups+, +:block_device_mappings+, +:key_name+, +:user_data+, +:kernel_id+, +:ramdisk_id+
as.create_launch_configuration('kd: CentOS.5.1-c.1', 'ami-08f41161', 'c1.medium', :key_name => 'tim', :security_groups => ['default'], :user_data => "Woohoo: CentOS.5.1-c", :block_device_mappings => [ { :device_name => '/dev/sdk', :ebs_snapshot_id => 'snap-145cbc7d', :ebs_delete_on_termination => true, :ebs_volume_size => 3, :virtual_name => 'ephemeral2' } ] ) #=> true
Create or update specified trigger. This call sets the parameters that governs when and how to scale an AutoScalingGroup. If the Trigger, within the scope of the caller‘s AWS account, specified already exists, it will be updated. If a trigger with a different name already exists, this call will fail.
Returns true or an exception.
Options: +:measure_name+, +:statistic+, +:period+, +:lower_threshold+, +:lower_breach_scale_increment+, +:upper_threshold+, +:upper_breach_scale_increment+, +:dimensions+, +:breach_duration+, +:unit+, +:custom_unit+
as.create_or_update_scaling_trigger('kd.tr.1', 'CentOS.5.1-c-array', :measure_name => 'CPUUtilization', :statistic => :average, :dimensions => { 'AutoScalingGroupName' => 'CentOS.5.1-c-array', 'Namespace' => 'AWS', 'Service' => 'EC2' }, :period => 60, :lower_threshold => 5, :lower_breach_scale_increment => -1, :upper_threshold => 60, :upper_breach_scale_increment => 1, :breach_duration => 300 ) #=> true
Deletes all configuration for this auto scaling group and also deletes the group. Returns true or raises an exception.
Delete launch configuration. Returns true or an exception.
as.delete_launch_configuration('CentOS.5.1') #=> true
Delete specified trigger. Returns true or an exception.
as.delete_trigger('kd.tr.1', 'CentOS.5.1-c-array') #=> true
Describe auto scaling groups. Returns a full description of the AutoScalingGroups from the given list. This includes all EC2 instances that are members of the group. If a list of names is not provided, then the full details of all AutoScalingGroups is returned. This style conforms to the EC2 DescribeInstances API behavior.
Describe all Launch Configurations. Returns an array of configurations.
as.describe_launch_configurations #=> [{:security_groups=>["default"], :ramdisk_id=>"", :user_data=>"V29vaG9vOiBDZW50T1MuNS4xLWM=", :instance_type=>"c1.medium", :block_device_mappings=> [{:virtual_name=>"ephemeral2", :device_name=>"/dev/sdk"}], :launch_configuration_name=>"kd: CentOS.5.1-c.1", :created_time=>"2010-03-29T10:00:32.742Z", :image_id=>"ami-08f41161", :key_name=>"tim", :kernel_id=>""}, ...]
Describe all Scaling Activities.
describe_scaling_activities('CentOS.5.1-c-array') #=> [{:cause=> "At 2009-05-28 10:11:35Z trigger kd.tr.1 breached high threshold value for CPUUtilization, 10.0, adjusting the desired capacity from 1 to 2. At 2009-05-28 10:11:35Z a breaching trigger explicitly set group desired capacity changing the desired capacity from 1 to 2. At 2009-05-28 10:11:40Z an instance was started in response to a difference between desired and actual capacity, increasing the capacity from 1 to 2.", :activity_id=>"067c9abb-f8a7-4cf8-8f3c-dc6f280457c4", :progress=>0, :description=>"Launching a new EC2 instance", :status_code=>"InProgress", :start_time=>Thu May 28 10:11:40 UTC 2009}, {:end_time=>Thu May 28 09:35:23 UTC 2009, :cause=> "At 2009-05-28 09:31:21Z a user request created an AutoScalingGroup changing the desired capacity from 0 to 1. At 2009-05-28 09:32:35Z an instance was started in response to a difference between desired and actual capacity, increasing the capacity from 0 to 1.", :activity_id=>"90d506ba-1b75-4d29-8739-0a75b1ba8030", :progress=>100, :description=>"Launching a new EC2 instance", :status_code=>"Successful", :start_time=>Thu May 28 09:32:35 UTC 2009}]}
Describe triggers. Returns a full description of the trigger in the specified Auto Scaling Group.
as.describe_triggers('CentOS.5.1-c-array') #=> [{:status=>"HighBreaching", :breach_duration=>300, :measure_name=>"CPUUtilization", :trigger_name=>"kd.tr.1", :period=>60, :lower_threshold=>0.0, :lower_breach_scale_increment=>-1, :dimensions=> {"Namespace"=>"AWS", "AutoScalingGroupName"=>"CentOS.5.1-c-array", "Service"=>"EC2"}, :statistic=>"Average", :upper_threshold=>10.0, :created_time=>Thu May 28 09:48:46 UTC 2009, :auto_scaling_group_name=>"CentOS.5.1-c-array", :upper_breach_scale_increment=>1}]
Incrementally describe Launch Configurations. Returns a full description of the launch configurations given the specified names. If no names are specified, then the full details of all launch configurations are returned.
Optional params: +:max_records+, +:next_token+.
# get max 100 first configurations as.incrementally_describe_launch_configurations #=> {:launch_configurations=> [{:created_time=>Thu May 28 09:31:20 UTC 2009, :kernel_id=>"", :launch_configuration_name=>"CentOS.5.1-c", :ramdisk_id=>"", :security_groups=>["default"], :key_name=>"kd-moo-test", :user_data=>"Woohoo: CentOS.5.1-c-array", :image_id=>"ami-08f41161", :block_device_mappings=>[], :instance_type=>"m1.small"}, ... ]} # list by 5 records incrementally_describe_launch_configurations(:max_records => 5) do |response| puts response.inspect true end
Incrementally describe Scaling Activities. Returns the scaling activities specified for the given group. If the input list is empty, all the activities from the past six weeks will be returned. Activities will be sorted by completion time. Activities that have no completion time will be considered as using the most recent possible time.
Optional params: +:max_records+, +:next_token+.
# get max 100 first activities as.incrementally_describe_scaling_activities('CentOS.5.1-c-array') #=> {:scaling_activities=> [{:cause=> "At 2009-05-28 10:11:35Z trigger kd.tr.1 breached high threshold value for CPUUtilization, 10.0, adjusting the desired capacity from 1 to 2. At 2009-05-28 10:11:35Z a breaching trigger explicitly set group desired capacity changing the desired capacity from 1 to 2. At 2009-05-28 10:11:40Z an instance was started in response to a difference between desired and actual capacity, increasing the capacity from 1 to 2.", :activity_id=>"067c9abb-f8a7-4cf8-8f3c-dc6f280457c4", :progress=>0, :description=>"Launching a new EC2 instance", :status_code=>"InProgress", :start_time=>Thu May 28 10:11:40 UTC 2009}, {:end_time=>Thu May 28 09:35:23 UTC 2009, :cause=> "At 2009-05-28 09:31:21Z a user request created an AutoScalingGroup changing the desired capacity from 0 to 1. At 2009-05-28 09:32:35Z an instance was started in response to a difference between desired and actual capacity, increasing the capacity from 0 to 1.", :activity_id=>"90d506ba-1b75-4d29-8739-0a75b1ba8030", :progress=>100, :description=>"Launching a new EC2 instance", :status_code=>"Successful", :start_time=>Thu May 28 09:32:35 UTC 2009}]} # list by 5 records incrementally_describe_scaling_activities('CentOS.5.1-c-array', :max_records => 5) do |response| puts response.inspect true end
Adjusts the desired size of the Capacity Group by using scaling actions, as necessary. When adjusting the size of the group downward, it is not possible to define which EC2 instances will be terminated. This also applies to any auto-scaling decisions that might result in the termination of instances.
Returns true or raises an exception.
as.set_desired_capacity('CentOS.5.1-c',3) #=> 3
This call will terminate the specified Instance. Optionally, the desired group size can be adjusted. If set to true, the default, the AutoScalingGroup size will decrease by one. If the AutoScalingGroup is associated with a LoadBalancer, the system will deregister the instance before terminating it. This call simply registers a termination request. The termination of the instance can not happen immediately.
Returns the activity to terminate the instance.
Updates the configuration for the given AutoScalingGroup. If MaxSize is lower than the current size, then there will be an implicit call to SetDesiredCapacity to set the group to the new MaxSize. The same is true for MinSize there will also be an implicit call to SetDesiredCapacity. All optional parameters are left unchanged if not passed in the request.
The new settings are registered upon the completion of this call. Any launch configuration settings will take effect on any triggers after this call returns. However, triggers that are currently in progress can not be affected. See key term Trigger.
Returns true or raises an exception.
Options: +:launch_configuration_name+, +:min_size+, +:max_size+, +:cooldown+, +:availability_zones+. (Amazon‘s notice: +:availability_zones+ is reserved for future use.)
as.update_auto_scaling_group('CentOS.5.1-c', :min_size => 1, :max_size => 4) #=> true