Skip to content
This repository has been archived by the owner on Sep 24, 2021. It is now read-only.

Let it work when no metadata is available #79

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pkg/aws/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package aws
import (
"io/ioutil"
"net/http"
"os"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cloudwatch"
Expand All @@ -11,8 +12,14 @@ import (
"k8s.io/klog"
)

// GetLocalRegion gets the region ID from the instance metadata.
// GetLocalRegion gets the region ID from the standard environment variables or instance metadata.
func GetLocalRegion() string {
if mp := os.Getenv("AWS_DEFAULT_REGION"); mp != "" {
return mp
}
if mp := os.Getenv("AWS_REGION"); mp != "" {
return mp
}
resp, err := http.Get("http://169.254.169.254/latest/meta-data/placement/availability-zone/")
if err != nil {
klog.Errorf("unable to get current region information, %v", err)
Expand Down