Class: AwsRegion
Overview
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.
Defined Under Namespace
Classes: AwsBucket, AwsCw, AwsDbInstance, AwsInstance, AwsSns
Constant Summary collapse
- REGIONS =
{'or' => "us-west-2", 'ca' => "us-west-1", 'va' => 'us-east-1'}
Instance Attribute Summary collapse
-
#account_id ⇒ Object
Returns the value of attribute account_id.
-
#cw ⇒ Object
Returns the value of attribute cw.
-
#ec2 ⇒ Object
Returns the value of attribute ec2.
-
#elb ⇒ Object
Returns the value of attribute elb.
-
#rds ⇒ Object
Returns the value of attribute rds.
-
#region ⇒ Object
Returns the value of attribute region.
-
#s3 ⇒ Object
Returns the value of attribute s3.
-
#sns ⇒ Object
Returns the value of attribute sns.
Instance Method Summary collapse
-
#create_bucket(options = {}) ⇒ AwsBucket
Construct new AwsBucket instance.
-
#create_cw_instance(options = {}) ⇒ AwsCw
Construct new CloudWatch instance.
-
#create_db_instance(options = {}) ⇒ AwsDbInstance
Construct new DB instance.
-
#create_instance(options = {}) ⇒ AwsInstance
Construct new EC2 instance.
- #create_sns_instance ⇒ Object
-
#find_buckets(options = {}) ⇒ Array<AwsBucket>
Search region for a bucket by name.
-
#find_db_instances(options = {}) ⇒ Array<AwsDbInstance>
Simple DB Instance finder.
-
#find_instances(options = {}) ⇒ Array<AwsInstance>
Simple EC2 Instance finder.
-
#initialize(region, account_id, access_key_id, secret_access_key, logger = nil) ⇒ AwsRegion
constructor
A new instance of AwsRegion.
Methods inherited from AwsBase
Constructor Details
#initialize(region, account_id, access_key_id, secret_access_key, logger = nil) ⇒ AwsRegion
Returns a new instance of AwsRegion.
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/aws_region.rb', line 22 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.new({:region => @region}) @rds = Aws::RDS.new({:region => @region}) @elb = Aws::ElasticLoadBalancing.new({:region => @region}) @cw = Aws::CloudWatch.new({:region => @region}) @s3 = Aws::S3.new({:region => @region}) @sns = Aws::SNS.new({:region => @region}) end |
Instance Attribute Details
#account_id ⇒ Object
Returns the value of attribute account_id.
15 16 17 |
# File 'lib/aws_region.rb', line 15 def account_id @account_id end |
#cw ⇒ Object
Returns the value of attribute cw.
15 16 17 |
# File 'lib/aws_region.rb', line 15 def cw @cw end |
#ec2 ⇒ Object
Returns the value of attribute ec2.
15 16 17 |
# File 'lib/aws_region.rb', line 15 def ec2 @ec2 end |
#elb ⇒ Object
Returns the value of attribute elb.
15 16 17 |
# File 'lib/aws_region.rb', line 15 def elb @elb end |
#rds ⇒ Object
Returns the value of attribute rds.
15 16 17 |
# File 'lib/aws_region.rb', line 15 def rds @rds end |
#region ⇒ Object
Returns the value of attribute region.
15 16 17 |
# File 'lib/aws_region.rb', line 15 def region @region end |
#s3 ⇒ Object
Returns the value of attribute s3.
15 16 17 |
# File 'lib/aws_region.rb', line 15 def s3 @s3 end |
#sns ⇒ Object
Returns the value of attribute sns.
15 16 17 |
# File 'lib/aws_region.rb', line 15 def sns @sns end |
Instance Method Details
#create_bucket(options = {}) ⇒ AwsBucket
Construct new AwsBucket instance
127 128 129 |
# File 'lib/aws_region.rb', line 127 def create_bucket(={}) AwsBucket.new(self, ) end |
#create_cw_instance(options = {}) ⇒ AwsCw
Construct new CloudWatch instance
119 120 121 |
# File 'lib/aws_region.rb', line 119 def create_cw_instance(={}) AwsCw.new(self, ) end |
#create_db_instance(options = {}) ⇒ AwsDbInstance
Construct new DB instance
111 112 113 |
# File 'lib/aws_region.rb', line 111 def create_db_instance(={}) AwsDbInstance.new(self, ) end |
#create_instance(options = {}) ⇒ AwsInstance
Construct new EC2 instance
103 104 105 |
# File 'lib/aws_region.rb', line 103 def create_instance(={}) AwsInstance.new(self, ) end |
#create_sns_instance ⇒ Object
131 132 133 |
# File 'lib/aws_region.rb', line 131 def create_sns_instance AwsSns.new(self) end |
#find_buckets(options = {}) ⇒ Array<AwsBucket>
Search region for a bucket by name
90 91 92 93 94 95 96 97 |
# File 'lib/aws_region.rb', line 90 def find_buckets(={}) buckets = [] _buckets = @s3.list_buckets() _buckets[:buckets].each do |b| buckets << AwsBucket.new(self, {id: b[:name]}) if b[:name] == [:bucket] end buckets end |
#find_db_instances(options = {}) ⇒ Array<AwsDbInstance>
Simple DB Instance finder. Can find using instance_id, or using :environment and :purpose instance tags which must both match.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/aws_region.rb', line 69 def find_db_instances(={}) instances = [] @rds.describe_db_instances[:db_instances].each do |i| instance = AwsDbInstance.new(self, {:instance => i}) if .has_key?(:instance_id) instance.id == [:instance_id] instances << instance elsif instance.[:environment] == [:environment] and instance.[:purpose] == [:purpose] instances << instance end end instances end |
#find_instances(options = {}) ⇒ Array<AwsInstance>
Simple EC2 Instance finder. Can find using instance_id, or using :environment and :purpose instance tags which must both match.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/aws_region.rb', line 44 def find_instances(={}) instances = [] @ec2.describe_instances[:reservations].each do |i| i.instances.each do |y| instance = AwsInstance.new(self, {:instance => y}) if instance.state != 'terminated' if .has_key?(:environment) and .has_key?(:purpose) instances << instance if instance.[:environment] == [:environment] and instance.[:purpose] == [:purpose] elsif .has_key?(:instance_id) instances << instance if instance.id == [:instance_id] end end end end return instances end |