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.
Add this line to your application's Gemfile:
gem 'ec2_meta'
And then execute:
$ bundle
Or install it yourself as:
$ gem install ec2_meta
# without options
client = Ec2Meta.client
# with all options
client = Ec2Meta.client(
logger: Logger.new($stdout),
fail_on_not_found: true
)
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. |
Currently supports all of Instance metadata
on Instance Metadata and User Data - Instance Metadata Categories at this time.
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.
MIT License
- Fork it ( https://github.com/[my-github-username]/ec2_meta/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request