Ec2Meta

Build Status Coverage Status Code Climate

Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file lib/ec2_meta. To experiment with that code, run bin/console for an interactive prompt.

Installation

Add this line to your application's Gemfile:

gem 'ec2_meta'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ec2_meta

Usage

Get Client

# without options
client = Ec2Meta.client

# with all options
client = Ec2Meta.client(
  logger: Logger.new($stdout),
  fail_on_not_found: true
)

options

name default description
logger Ec2Meta::NullLogger.new Pass your logger if you want
fail_on_not_found false If set true, raise error on metadata not found.

Get Meta

Currently supports all of Instance metadata on Instance Metadata and User Data - Instance Metadata Categories at this time.

Supported Meta Apis

Sample Code

You can fetch meta data like below.

# fetch ami-id
client.ami_id

# fetch hostname
client.hostname

# fetch vpc_id for first network interface
client.network.interfaces.macs(0).vpc_id

When meta data not found, return nil if fail_on_not_found is not true.

License

MIT License

Contributing

  1. Fork it ( https://github.com/[my-github-username]/ec2_meta/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request