Skip to content

Commit d796ea8

Browse files
authored
fixed and improved region detection within queue url (#403)
* fixed and improved region detection within queue url * add debug log for queue-url region detectio n
1 parent 4a37023 commit d796ea8

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

pkg/config/config.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"strconv"
2121
"strings"
2222

23+
"github.com/aws/aws-sdk-go/aws/endpoints"
2324
"github.com/aws/aws-sdk-go/aws/session"
2425
"github.com/rs/zerolog/log"
2526
)
@@ -193,7 +194,8 @@ func ParseCliArgs() (config Config, err error) {
193194
if config.AWSRegion != "" {
194195
sess.Config.Region = &config.AWSRegion
195196
} else if *sess.Config.Region == "" && config.QueueURL != "" {
196-
config.AWSRegion = strings.Split(config.QueueURL, ".")[1]
197+
config.AWSRegion = getRegionFromQueueURL(config.QueueURL)
198+
log.Debug().Str("Retrieved AWS region from queue-url: \"%s\"", config.AWSRegion)
197199
sess.Config.Region = &config.AWSRegion
198200
} else {
199201
config.AWSRegion = *sess.Config.Region
@@ -397,3 +399,14 @@ func isConfigProvided(cliArgName string, envVarName string) bool {
397399
})
398400
return cliArgProvided
399401
}
402+
403+
func getRegionFromQueueURL(queueURL string) string {
404+
for _, partition := range endpoints.DefaultPartitions() {
405+
for regionID := range partition.Regions() {
406+
if strings.Contains(queueURL, regionID) {
407+
return regionID
408+
}
409+
}
410+
}
411+
return ""
412+
}

0 commit comments

Comments
 (0)