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.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# 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 |
Instance Attribute Details
#account_id ⇒ Object
Returns the value of attribute account_id.
16 17 18 |
# File 'lib/aws_region.rb', line 16 def account_id @account_id end |
#cw ⇒ Object
Returns the value of attribute cw.
16 17 18 |
# File 'lib/aws_region.rb', line 16 def cw @cw end |
#ec2 ⇒ Object
Returns the value of attribute ec2.
16 17 18 |
# File 'lib/aws_region.rb', line 16 def ec2 @ec2 end |
#elb ⇒ Object
Returns the value of attribute elb.
16 17 18 |
# File 'lib/aws_region.rb', line 16 def elb @elb end |
#rds ⇒ Object
Returns the value of attribute rds.
16 17 18 |
# File 'lib/aws_region.rb', line 16 def rds @rds end |
#region ⇒ Object
Returns the value of attribute region.
16 17 18 |
# File 'lib/aws_region.rb', line 16 def region @region end |
#s3 ⇒ Object
Returns the value of attribute s3.
16 17 18 |
# File 'lib/aws_region.rb', line 16 def s3 @s3 end |
#sns ⇒ Object
Returns the value of attribute sns.
16 17 18 |
# File 'lib/aws_region.rb', line 16 def sns @sns end |
Instance Method Details
#create_bucket(options = {}) ⇒ AwsBucket
Construct new AwsBucket instance
128 129 130 |
# File 'lib/aws_region.rb', line 128 def create_bucket(={}) AwsBucket.new(self, ) end |
#create_cw_instance(options = {}) ⇒ AwsCw
Construct new CloudWatch instance
120 121 122 |
# File 'lib/aws_region.rb', line 120 def create_cw_instance(={}) AwsCw.new(self, ) end |
#create_db_instance(options = {}) ⇒ AwsDbInstance
Construct new DB instance
112 113 114 |
# File 'lib/aws_region.rb', line 112 def create_db_instance(={}) AwsDbInstance.new(self, ) end |
#create_instance(options = {}) ⇒ AwsInstance
Construct new EC2 instance
104 105 106 |
# File 'lib/aws_region.rb', line 104 def create_instance(={}) AwsInstance.new(self, ) end |
#create_sns_instance ⇒ Object
132 133 134 |
# File 'lib/aws_region.rb', line 132 def create_sns_instance AwsSns.new(self) end |
#find_buckets(options = {}) ⇒ Array<AwsBucket>
Search region for a bucket by name
91 92 93 94 95 96 97 98 |
# File 'lib/aws_region.rb', line 91 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.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/aws_region.rb', line 70 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.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/aws_region.rb', line 45 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 |