Sha256: e35c9718c0715fb7bb64d68fa57302be19eaa93410f6c6922c1c53ce413c9884

Contents?: true

Size: 992 Bytes

Versions: 25

Compression:

Stored size: 992 Bytes

Contents

module Jets
  class AwsInfo
    extend Memoist
    include AwsServices

    def region
      return 'us-east-1' if test?

      region = nil

      # First try to get it from the ~/.aws/config
      region = `aws configure get region`.strip rescue nil
      return region if region

      # Second try the metadata endpoint, should be available on AWS Lambda environment
      # https://stackoverflow.com/questions/4249488/find-region-from-within-an-ec2-instance
      begin
        az = `curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone`
        region = az.strip.chop # remove last char
      rescue
      end
      return region if region

      ENV['JETS_AWS_REGION'] || 'us-east-1' # default if all else fails
    end
    memoize :region

    # aws sts get-caller-identity
    def account
      return '123456789' if test?
      sts.get_caller_identity.account
    end
    memoize :account

    def test?
      ENV['TEST'] || ENV['CIRCLECI']
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
jets-0.8.17 lib/jets/aws_info.rb
jets-0.8.15 lib/jets/aws_info.rb
jets-0.8.14 lib/jets/aws_info.rb
jets-0.8.13 lib/jets/aws_info.rb
jets-0.8.12 lib/jets/aws_info.rb
jets-0.8.11 lib/jets/aws_info.rb
jets-0.8.10 lib/jets/aws_info.rb
jets-0.8.9 lib/jets/aws_info.rb
jets-0.8.8 lib/jets/aws_info.rb
jets-0.8.6 lib/jets/aws_info.rb
jets-0.8.5 lib/jets/aws_info.rb
jets-0.8.4 lib/jets/aws_info.rb
jets-0.8.3 lib/jets/aws_info.rb
jets-0.8.2 lib/jets/aws_info.rb
jets-0.8.1 lib/jets/aws_info.rb
jets-0.8.0 lib/jets/aws_info.rb
jets-0.7.1 lib/jets/aws_info.rb
jets-0.7.0 lib/jets/aws_info.rb
jets-0.6.9 lib/jets/aws_info.rb
jets-0.6.8 lib/jets/aws_info.rb