Kushal Das

FOSS and life. Kushal Das talks here.

kushal76uaid62oup5774umh654scnu5dwzh4u2534qxhcbi4wbab3ad.onion

Using golang with Eucalyptus

Here is an example code to start a new instance in your Eucalyptus cloud using golang. We are using goamz library.

package main

import (
	"fmt"
	"github.com/mitchellh/goamz/aws"
	"github.com/mitchellh/goamz/ec2"
	"net/http"
)

func main() {
	DefaultClient := &http.Client{
		Transport: &http.Transport{
			Proxy: http.ProxyFromEnvironment,
		},
	}

	auth := aws.Auth{"AKI98", "5KZb4GbQ", ""}
	mec2 := ec2.NewWithClient(
		auth,
		aws.Region{EC2Endpoint: "http://euca-ip:8773/services/Eucalyptus"},
		DefaultClient,
	)

	options := ec2.RunInstances{
		ImageId:      "emi-F5433303",
		InstanceType: "m1.xlarge",
		KeyName:      "foo",
	}
	resp, _ := mec2.RunInstances(&options)

	fmt.Println(resp)

}