7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/cfn_manage/aws_credentials.rb', line 7
def self.get_session_credentials(session_name)
session_name = "#{session_name.gsub('_','-')}-#{Time.now.getutc.to_i}"
if session_name.length > 64
session_name = session_name[-64..-1]
end
assume_role = ENV['AWS_ASSUME_ROLE'] or nil
if not assume_role.nil?
return Aws::AssumeRoleCredentials.new(
role_arn: assume_role,
role_session_name: session_name
)
end
if ENV.key?('CFN_AWS_PROFILE')
return Aws::SharedCredentials.new(profile_name: ENV['CFN_AWS_PROFILE'])
end
credentials = Aws::InstanceProfileCredentials.new(retries: 2, http_open_timeout:1)
return credentials unless credentials.credentials.access_key_id.nil?
return Aws::SharedCredentials.new()
end
|