class AwsRegion
AwsRegion
is a simplified wrapper on top of a few of the Aws core objects The main goal is to expose a extremely simple interface for some our most frequently used Aws facilities.
Constants
- REGIONS
Attributes
Public Class Methods
@param region [String] must be one of the keys of the {AwsRegion::REGIONS REGIONS} static hash @param account_id
[String] Aws account id @param access_key_id [String] Aws access key id @param secret_access_key [String] Aws secret access key
# File lib/aws_region.rb, line 23 def initialize(region, account_id, access_key_id, secret_access_key, logger = nil) @logger = logger @region = REGIONS[region] @account_id = account_id Aws.config = {:access_key_id => access_key_id, :secret_access_key => secret_access_key} @ec2 = Aws::EC2::Client.new(region: @region) @rds = Aws::RDS::Client.new(region: @region) @elb = Aws::ElasticLoadBalancing::Client.new(region: @region) @cw = Aws::CloudWatch::Client.new(region: @region) @s3 = Aws::S3::Client.new(region: @region) @sns = Aws::SNS::Client.new(region: @region) end
Public Instance Methods
Construct new AwsBucket
instance
@param options [Hash] containing initialization parameters. See {AwsBucket#initialize} @return [AwsBucket]
# File lib/aws_region.rb, line 128 def create_bucket(options={}) AwsBucket.new(self, options) end
Construct new CloudWatch instance
@param options [Hash] containing initialization parameters. See {AwsCw#initialize} @return [AwsCw]
# File lib/aws_region.rb, line 120 def create_cw_instance(options={}) AwsCw.new(self, options) end
Construct new DB instance
@param options [Hash] containing initialization parameters. See {AwsDbInstance#initialize} @return [AwsDbInstance]
# File lib/aws_region.rb, line 112 def create_db_instance(options={}) AwsDbInstance.new(self, options) end
Construct new EC2 instance
@param options [Hash] containing initialization parameters. See {AwsInstance#initialize} @return [AwsInstance]
# File lib/aws_region.rb, line 104 def create_instance(options={}) AwsInstance.new(self, options) end
# File lib/aws_region.rb, line 132 def create_sns_instance AwsSns.new(self) end
Search region for a bucket by name
@param options [Hash] containing search criteria. Values can be:
* :bucket - Bucket name
@return [Array<AwsBucket>] instances found to match criteria
# File lib/aws_region.rb, line 91 def find_buckets(options={}) buckets = [] _buckets = @s3.list_buckets() _buckets[:buckets].each do |b| buckets << AwsBucket.new(self, {id: b[:name]}) if b[:name] == options[:bucket] end buckets end
Simple DB Instance finder. Can find using instance_id, or using :environment and :purpose instance tags which must both match.
@param options [Hash] containing search criteria. Values can be:
* :instance_id - identifies an exact instance * :environment - instance tag * :purpose - instance tag
@return [Array<AwsDbInstance>] instances found to match criteria
# File lib/aws_region.rb, line 70 def find_db_instances(options={}) instances = [] @rds.describe_db_instances[:db_instances].each do |i| instance = AwsDbInstance.new(self, {:instance => i}) if options.has_key?(:instance_id) instance.id == options[:instance_id] instances << instance elsif instance.tags[:environment] == options[:environment] and instance.tags[:purpose] == options[:purpose] instances << instance end end instances end
Simple EC2 Instance finder. Can find using instance_id, or using :environment and :purpose instance tags which must both match.
@param options [Hash] containing search criteria. Values can be:
* :instance_id - identifies an exact instance * :environment - instance tag * :purpose - instance tag
@return [Array<AwsInstance>] instances found to match criteria
# File lib/aws_region.rb, line 45 def find_instances(options={}) instances = [] @ec2.describe_instances[:reservations].each do |i| i.instances.each do |y| instance = AwsInstance.new(self, {:instance => y}) if instance.state != 'terminated' if options.has_key?(:environment) and options.has_key?(:purpose) instances << instance if instance.tags[:environment] == options[:environment] and instance.tags[:purpose] == options[:purpose] elsif options.has_key?(:instance_id) instances << instance if instance.id == options[:instance_id] end end end end return instances end