簡體   English   中英

Amazon SQS FIFO隊列發送消息失敗

[英]Amazon SQS FIFO Queue sending message failed

我們正在嘗試向AWS FIFO隊列發送消息。 我們已經有將代碼發送到SQS標准隊列的代碼的工作版本。

Python代碼(我們的要求是不要使用SDK): 完整版本4簽名過程(Python)的示例

對於標准隊列,我們​​使用以下參數

    method = 'GET'
    service = 'sqs'
    host = 'sqs.us-west-2.amazonaws.com'
    region = 'us-west-2'
    endpoint = 'https://sqs.us-west-2.amazonaws.com/xxxxxx/TestQueue'
    request_parameters = 'Action=SendMessage&MessageBody=mytest&Version=2012-11-05'
    canonical_uri = '/xxxxxx/TestQueue'

對於FIFO隊列,我們​​使用相同的代碼,並進行了如下修改

method = 'GET'
service = 'sqs'
host = 'sqs.us-west-2.amazonaws.com'
region = 'us-west-2'
endpoint = 'https://sqs.us-west-2.amazonaws.com/xxxxxxx/Test.fifo'
request_parameters = 'Action=SendMessage&MessageBody=mytest&MessageGroupId=test&MessageDeduplicationId=ttte&Version=2012-11-05'
canonical_uri = '/xxxxxxx/Test.fifo'

但這是失敗的。 我們缺少任何東西嗎,有人可以幫助我們嗎?

Response code: 403

<?xml version="1.0"?><ErrorResponse xmlns="http://queue.amazonaws.com/doc/2012-11-05/"><Error><Type>Sender</Type><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.

簽名算法要求您在簽名之前按詞法對參數進行排序。 這就是為什么術語的規范是在描述中使用的部分“規范的查詢字符串。” 它們不一定需要在實際請求中發送到服務器進行排序,但是必須進行排序才能簽名以產生正確的結果。

MessageGroupId必須在MessageDeduplicationId之后,而不是之前。

您鏈接到的頁面上的代碼示例中提到了這一點:

# Step 3: Create the canonical query string. In this example (a GET request),
# request parameters are in the query string. Query string values must
# be URL-encoded (space=%20). The parameters must be sorted by name.
# For this example, the query string is pre-formatted in the request_parameters variable.

比此簡化示例更好的實現可能是將參數作為字典並進行排序以構建規范的查詢字符串。 更好的實現可能還會自動處理鍵和值的url轉義。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM