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
- .client_args ⇒ Object
- .credentials ⇒ Object
- .ec2_credentials ⇒ Object
- .ecs_credentials ⇒ Object
- .environment_credentials ⇒ Object
- .profile ⇒ Object
- .profile? ⇒ Boolean
- .profile_credentials ⇒ Object
- .region ⇒ Object
Class Method Details
.client_args ⇒ Object
24 25 26 |
# File 'lib/rrx_config/aws.rb', line 24 def client_args { region:, credentials: } end |
.credentials ⇒ Object
20 21 22 |
# File 'lib/rrx_config/aws.rb', line 20 def credentials @credentials ||= profile_credentials || environment_credentials || ecs_credentials || ec2_credentials end |
.ec2_credentials ⇒ Object
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_credentials ⇒ Object
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_credentials ⇒ Object
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 |
.profile ⇒ Object
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
12 13 14 |
# File 'lib/rrx_config/aws.rb', line 12 def profile? ENV.include?(PROFILE_VARIABLE) end |
.profile_credentials ⇒ Object
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 |
.region ⇒ Object
28 29 30 |
# File 'lib/rrx_config/aws.rb', line 28 def region ENV.fetch(REGION_VARIABLE, REGION_DEFAULT) end |