Skip to content

Instantly share code, notes, and snippets.

@SaschaMoellering
Created May 27, 2014 08:28
Show Gist options
  • Save SaschaMoellering/fa42e263d754c0b728ee to your computer and use it in GitHub Desktop.
Save SaschaMoellering/fa42e263d754c0b728ee to your computer and use it in GitHub Desktop.
require 'net/http'
link = URI.parse('http://169.254.169.254/latest/meta-data/instance-id')
request = Net::HTTP::Get.new(link.path)
begin
response = Net::HTTP.start(link.host, link.port) { |http|
http.read_timeout = 5 #Default is 60 seconds
http.request(request)
}
rescue Exception => e
puts e.message
puts e.class
end
▶ ruby timeout.rb
Operation timed out - connect(2)
Errno::ETIMEDOUT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment