Module: RrxConfig::Aws

Defined in:
lib/rrx_config/aws.rb

Constant Summary collapse

PROFILE_VARIABLE =
'RRX_AWS_PROFILE'
REGION_VARIABLE =
'RRX_AWS_REGION'
REGION_DEFAULT =
'us-west-2'
PROFILE_DEFAULT =
'default'
ECS_METADATA_VARIABLE =
'ECS_CONTAINER_METADATA_URI_V4'

Class Method Summary collapse

Class Method Details

.client_argsObject



24
25
26
# File 'lib/rrx_config/aws.rb', line 24

def client_args
  { region:, credentials: }
end

.credentialsObject



20
21
22
# File 'lib/rrx_config/aws.rb', line 20

def credentials
  @credentials ||= profile_credentials || environment_credentials || ecs_credentials || ec2_credentials
end

.ec2_credentialsObject



56
57
58
59
60
# File 'lib/rrx_config/aws.rb', line 56

def ec2_credentials
  RrxConfig.logger.info 'Using EC2 credentials'
  require 'aws-sdk-core/instance_profile_credentials'
  ::Aws::InstanceProfileCredentials.new
end

.ecs_credentialsObject



48
49
50
51
52
53
54
# File 'lib/rrx_config/aws.rb', line 48

def ecs_credentials
  if ENV.include?(ECS_METADATA_VARIABLE)
    RrxConfig.logger.info 'Using ECS credentials'
    require 'aws-sdk-core/ecs_credentials'
    ::Aws::ECSCredentials.new
  end
end

.environment_credentialsObject



40
41
42
43
44
45
46
# File 'lib/rrx_config/aws.rb', line 40

def environment_credentials
  if ENV.include?('AWS_ACCESS_KEY_ID')
    require 'aws-sdk-core/credentials'
    RrxConfig.logger.info 'Using explicit credentials'
    ::Aws::Credentials.new(ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY'])
  end
end

.profileObject



16
17
18
# File 'lib/rrx_config/aws.rb', line 16

def profile
  ENV.fetch(PROFILE_VARIABLE, PROFILE_DEFAULT) unless Rails.env.production?
end

.profile?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/rrx_config/aws.rb', line 12

def profile?
  ENV.include?(PROFILE_VARIABLE)
end

.profile_credentialsObject



32
33
34
35
36
37
38
# File 'lib/rrx_config/aws.rb', line 32

def profile_credentials
  if profile?
    RrxConfig.logger.info 'Using shared credentials'
    require 'aws-sdk-core/shared_credentials'
    ::Aws::SharedCredentials.new(profile_name: profile)
  end
end

.regionObject



28
29
30
# File 'lib/rrx_config/aws.rb', line 28

def region
  ENV.fetch(REGION_VARIABLE, REGION_DEFAULT)
end