I have an SQS URL which includes region as well. I am using official Go SDK to perform operations on this SQS which require AWS region to initialize the session. Currently, I have written a utility function to parse the URL and return AWS region.
Sample URL: https://sqs.us-east-1.amazonaws.com/774557911234/my_sqs_name
Sample Initialization code:
sess, err := session.NewSession()
if err != nil {
return
}
s := sqs.New(sess, aws.NewConfig().WithRegion(getRegionFromSQSURL(config.SQSURL))
Sample function to get region from URL
func getRegionFromSQSURL(url string) string {
return strings.Split(url, ".")[1]
}
Just wondering if this is the correct approach.
Would there be any case where SQS URL will have a different region in URL than the region in which SQS exists?
Should I just add one more environment variable to be set in the service?