Golang: Get EC2 AWS instance region

Following is the golang code to get the region of an EC2 machine in AWS.

package main

import (

func getRegion() string{
    link := ""
    response, err := http.Get(link)
    if err != nil {
    defer response.Body.Close()

    //block forever at the next line
    content, _ := ioutil.ReadAll(response.Body)

    return string(content)

func main() {
    aws_region := getRegion()


Leave a Reply

Your email address will not be published. Required fields are marked *