lib/pec2/ec2.rb in pec2-0.6.2 vs lib/pec2/ec2.rb in pec2-0.6.3
- old
+ new
@@ -10,14 +10,13 @@
end
module Pec2
class Ec2
- def initialize
+ def initialize(profile:)
@logger = Logger.new(STDOUT)
- ENV['AWS_REGION'] = ENV['AWS_REGION'] || get_document['region']
- @ec2 = Aws::EC2::Client.new
+ @ec2 = Aws::EC2::Client.new(get_param(profile))
end
def instances_hash(condition)
filter = []
condition.each do |key, value|
@@ -42,8 +41,24 @@
}
return result
rescue Timeout::Error => e
raise "not EC2 instance"
end
+ end
+
+ private
+
+ def get_param(profile)
+ param = {}
+ region = if profile
+ param[:profile] = profile
+ else
+ param[:region] = if ENV['AWS_REGION']
+ ENV['AWS_REGION']
+ else
+ Metadata.get_document['region']
+ end
+ end
+ param
end
end
end