Sha256: bdbdd71832ed5101864d7eefe3718be933082d5b7ec02f070545a47068232195

Contents?: true

Size: 655 Bytes

Versions: 2

Compression:

Stored size: 655 Bytes

Contents

require 'logger'
require 'open-uri'
require 'json'

module Tagenv
  module Ec2
    class Metadata
      def self.get_metadata(path)
        begin
          result = {}
          ::Timeout.timeout(TIME_OUT) {
            body = open('http://169.254.169.254' + path).read
            return body
          }
          return result
        rescue Timeout::Error => e
          raise "not EC2 instance"
        end
      end

      def self.get_document
        JSON.parse(get_metadata('/latest/dynamic/instance-identity/document/'))
      end

      def self.get_instance_id
        get_metadata('/latest/meta-data/instance-id')
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tagenv-0.1.1 lib/tagenv/ec2/metadata.rb
tagenv-0.1.0 lib/tagenv/ec2/metadata.rb