Last active
October 20, 2017 00:28
-
-
Save prasincs/bd9ef688912acedc95248c2761c474bd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"log" | |
"os" | |
"github.com/aws/aws-sdk-go/aws/ec2metadata" | |
"github.com/aws/aws-sdk-go/aws/session" | |
) | |
func main() { | |
sess := session.Must(session.NewSession()) | |
meta := ec2metadata.New(sess) | |
identityDocument, err := meta.GetInstanceIdentityDocument() | |
if err != nil { | |
log.Fatalf("Failed to get instance identity %s", err) | |
} | |
content, err := json.MarshalIndent(identityDocument, "", " ") | |
fmt.Println(string(content)) | |
if len(os.Args) > 0 { | |
for _, path := range os.Args[1:] { | |
str, err := meta.GetMetadata(path) | |
if err != nil { | |
log.Printf("Failed to query metadata for %s. %s", path, err) | |
}else { | |
fmt.Printf("%s => %s\n", path, str) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment