File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,16 @@ func ValidateARN(arnString string) bool {
28
28
return true
29
29
}
30
30
31
+ // Helper function to get region from ARNs
32
+ func GetRegionFromARN (arnString string ) string {
33
+ arn , err := arn .Parse (arnString )
34
+ if err != nil {
35
+ log .Warnf ("The ARN supplied as argument does not parse successfully: %s" , arnString )
36
+ return ""
37
+ }
38
+ return arn .Region
39
+ }
40
+
31
41
// InstanceProfileArn uses the EC2 metadata API to find the role for
32
42
// the instance.
33
43
func InstanceProfileArn (svc * ec2metadata.EC2Metadata ) (arn.ARN , error ) {
Original file line number Diff line number Diff line change @@ -118,6 +118,13 @@ func main() {
118
118
}),
119
119
)
120
120
121
+ // if region is not configured according to AWS SDK docs, but ARN prefix is provided
122
+ // the region will be parsed from the ARN prefix
123
+ if config .Region == nil && * arnPrefix != "" {
124
+ arnRegion := arnutil .GetRegionFromARN (* arnPrefix )
125
+ config .Region = & arnRegion
126
+ }
127
+
121
128
session , err := session .NewSessionWithOptions (session.Options {
122
129
Config : * config ,
123
130
})
You can’t perform that action at this time.
0 commit comments