Project

ec2_meta

0.0
No commit activity in last 3 years
No release in over 3 years
AWS Metadata API client library. This gem is available only on AWS EC2 instance.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
~> 10.0
~> 3.2
~> 0.52
~> 0.9
~> 1.21
~> 0.9.11
~> 0.9
 Project Readme

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