Amazon SQS FIFO队列发送消息失败

时间:2018-06-28 03:59:00

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

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

Python代码(我们的要求是不要使用SDK):Examples of the Complete Version 4 Signing Process (Python)

对于标准队列,我们​​使用以下参数

pygame.gfxdraw.filled_circle(screen, rect.centerx, rect.centery, 80, light_green)
pygame.gfxdraw.aacircle(screen, rect.centerx, rect.centery, 80, light_green)

对于FIFO队列,我们​​使用相同的代码,并进行了如下修改

    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'

1 个答案:

答案 0 :(得分: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.

比这个简化的示例更好的实现可能是将参数作为字典并进行排序,以构建规范的查询字符串。更好的实现方式可能还会自动处理键和值的网址转义。

相关问题