ec2dynamicdata

package module
v0.0.0-...-56f69f1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2015 License: MIT Imports: 8 Imported by: 3

README

EC2Dynamicdata GoDoc

ec2dynamicdata is an handy package to retrieve the ec2 dynamic data and meta data information via simple API. The API can change in the future, please vendor it in your code base.

Install

go get github.com/koding/ec2dynamicdata

Usage

There are two main functions, one for dynamicdata and one for metadata. Below is an example code usage:

data, _ := ec2dynamicdata.Get()
/* data output:
{
  "accountId" : "123456789",
  "instanceId" : "i-abc123",
  "billingProducts" : null,
  "instanceType" : "t2.micro",
  "imageId" : "ami-9871234",
  "kernelId" : null,
  "ramdiskId" : null,
  "architecture" : "x86_64",
  "pendingTime" : "2015-07-21T09:10:42Z",
  "region" : "eu-west-1",
  "version" : "2010-08-31",
  "availabilityZone" : "eu-west-1b",
  "devpayProductCodes" : null,
  "privateIp" : "10.0.123.456"
}
*/

fmt.Println(data.ImageID)  // ami-9871234
fmt.Println(data.AccountID // 123456789

amiID, _ := ec2dynamicdata.GetMetadata(ec2dynamicdata.AmiId)
instanceID, _ := ec2dynamicdata.GetMetadata(ec2dynamicdata.InstanceId)
// and so on ...

License

The MIT License (MIT) - see LICENSE.md for more details

Documentation

Overview

Package ec2dynamicdata gets ec2 dynamic data or meta data for the current running ec2 host

Index

Constants

This section is empty.

Variables

View Source
var (
	// DialTimeout holds timeout value for ec2 dynamic data calls
	DialTimeout = time.Second * 5
)

Functions

func GetMetadata

func GetMetadata(item Item) (string, error)

GetMetadata returns the value for the given meta data item.

Types

type Data

type Data struct {
	InstanceID         string      `json:"instanceId"`
	BillingProducts    interface{} `json:"billingProducts"`
	ImageID            string      `json:"imageId"`
	Architecture       string      `json:"architecture"`
	PendingTime        time.Time   `json:"pendingTime"`
	InstanceType       string      `json:"instanceType"`
	AccountID          string      `json:"accountId"`
	KernelID           interface{} `json:"kernelId"`
	RamdiskID          interface{} `json:"ramdiskId"`
	Region             string      `json:"region"`
	Version            string      `json:"version"`
	AvailabilityZone   string      `json:"availabilityZone"`
	PrivateID          string      `json:"privateIp"`
	DevpayProductCodes interface{} `json:"devpayProductCodes"`
}

Data holds dynamic data about current ec2 host

func Get

func Get() (*Data, error)

Get returns EC2 dynamic data

type Err

type Err struct {
	Err      error
	Original error
}

Err wraps any possible errors for api call

func (*Err) Error

func (e *Err) Error() string

Error implements the error interface.

type Item

type Item int

Item defines a single resource that can be retrieved from a met-data endpoint

const (
	AmiId Item = iota + 1
	AmiLaunchIndex
	AmiManifestPath
	Hostname
	InstanceAction
	InstanceId
	InstanceType
	LocalHostname
	LocalIPv4
	Mac
	Profile
	PublicIPv4
	PublicHostname
	ReservationId
	SecurityGroups
)

This is an incomplete list because other items have sub items. So if you need them just modify the source to have a support to it. But probably it's an overkill and you'll not going to need it :)

func (Item) String

func (i Item) String() string

String implements the Stringer interface. It's also used to construct the meta-data endpoint

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL