diff --git a/lib/cap-ec2/ec2-handler.rb b/lib/cap-ec2/ec2-handler.rb index cc32a6e..4a248da 100644 --- a/lib/cap-ec2/ec2-handler.rb +++ b/lib/cap-ec2/ec2-handler.rb @@ -14,9 +14,16 @@ def initialize end def ec2_connect(region=nil) + credentials = if fetch(:ec2_profile) + Aws::SharedCredentials.new(profile_name: fetch(:ec2_profile)) + else + Aws::Credentials.new( + fetch(:ec2_access_key_id), + fetch(:ec2_secret_access_key), + ) + end Aws::EC2::Client.new( - access_key_id: fetch(:ec2_access_key_id), - secret_access_key: fetch(:ec2_secret_access_key), + credentials: credentials, region: region ) end diff --git a/lib/cap-ec2/utils.rb b/lib/cap-ec2/utils.rb index 2c7a38d..9679ba7 100644 --- a/lib/cap-ec2/utils.rb +++ b/lib/cap-ec2/utils.rb @@ -46,14 +46,6 @@ def self.contact_point(instance) end def load_config - if fetch(:ec2_profile) - credentials = Aws::SharedCredentials.new(profile_name: fetch(:ec2_profile)).credentials - if credentials - set :ec2_access_key_id, credentials.access_key_id - set :ec2_secret_access_key, credentials.secret_access_key - end - end - config_location = File.expand_path(fetch(:ec2_config), Dir.pwd) if fetch(:ec2_config) if config_location && File.exists?(config_location) config = YAML.load(ERB.new(File.read(fetch(:ec2_config))))