duanpu2272 2018-01-23 09:33
浏览 58
已采纳

是否可以从SQS网址获取AWS区域?

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?

  • 写回答

3条回答 默认 最新

  • doudi1750 2018-01-23 09:39
    关注

    Cited from here: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-queue-message-identifiers.html

    Important

    In your system, always store the entire queue URL exactly as Amazon SQS returns it to you when you create the queue (for example, http://sqs.us-east-2.amazonaws.com/123456789012/queue2). Don't build the queue URL from its separate components each time you need to specify the queue URL in a request because Amazon SQS can change the components that make up the queue URL.

    As explained, they can change the structure of the URL sometimes in the future for whatever reason. Queue region will probably still stay somewhere in the url, but not necessarily in the spot that you expect it to be.

    So, all thinks considered, I think that introducing new environment variable is the right way to go.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景