From 650d6061b7de099959231c75ffdbd06f0cfe763a Mon Sep 17 00:00:00 2001 From: Eugene Babichev Date: Mon, 29 Mar 2021 15:44:12 +1100 Subject: [PATCH] Let it work when no metadata is available --- pkg/aws/util.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/aws/util.go b/pkg/aws/util.go index 7bd8a1b..a2756e3 100644 --- a/pkg/aws/util.go +++ b/pkg/aws/util.go @@ -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" @@ -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)