ec2-metadata

Install

$ [sudo] gem install ec2-

As ruby library

ec-metadata provides a way to access meta-data and user-data on EC2 instance.

[:instance_id]
['instance_id']
[:'instance-id']
['instance-id']

If you want to specify API version, you can get data like this:

['1.0'][:instance_id]

If you can also get it like this:

['1.0']['meta-data'][:instance_id]

For more detail, see also: github.com/akm/ec2-metadata/blob/master/spec/introduction_spec.rb

As a command

ec2-metadata shows various meta-data and user-data

$ ec2-

For more detail, type

$ ec2- -h

Dummy YAML

If you want to access meta-data or user-data not on EC2 Instance like on it, make one of these files

./config/.yml
./.yml
~/ec2_metadata.yml
/etc/.yml

Dummy YAML file must be like output of ec2-metadata on EC2 instance. You can export it on EC2 instance like this:

$ ec2-medatata > .yml
$ cp .yml /path/to/dir/for/non/ec2/instance

Or if you don’t have EC2 instance, you can get an example by

$ ec2- -d

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2010 Takeshi AKIMA. See LICENSE for details.