【问题标题】:Amazon SQS FIFO Queue sending message failedAmazon SQS FIFO 队列发送消息失败
【发布时间】:2018-06-28 19:24:21
【问题描述】:

我们正在尝试向 AWS FIFO 队列发送消息。我们已经有了将消息发送到 SQS 标准队列的代码的工作版本。

Python代码(我们的要求是不使用SDK):Examples of the Complete Version 4 Signing Process (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'

对于先进先出队列,我们​​使用相同的代码,另外修改如下

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.

【问题讨论】:

  • 不知道为什么这被否决了 - 这是一个很好的、明确的、可回答的问题,包括尝试和预期与观察到的行为。答案恰好埋在文档中。希望我能看到更多这样的问题。

标签: python amazon-web-services amazon-sqs fifo signing


【解决方案1】:

签名算法要求您在签名之前对参数进行词法排序。这就是为什么在描述“规范查询字符串”时使用术语 canonical 的部分原因。它们不一定需要在实际请求中发送到服务器并进行排序,但必须对它们进行排序以进行签名以产生正确的结果。

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 转义。

【讨论】:

    猜你喜欢
    • 2018-08-29
    • 2017-04-12
    • 2019-04-11
    • 2017-02-07
    • 1970-01-01
    • 2018-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多