Boto3 无法从 SQS 读取指定数量的消息

Boto3 is failing to read the specified number of messages from SQS

我在 SQS 中有一个队列,其中有两条可用消息。

$ aws sqs get-queue-attributes --queue-url https://sqs.eu-west-1.amazonaws.com/<id>/MyQueue --attribute-names ApproximateNumberOfMessages
{
    "Attributes": {
        "ApproximateNumberOfMessages": "2"
    }
}

每当我尝试在Python中阅读它们时,只返回一个,我不知道为什么...

In [23]: sqs = boto3.resource('sqs')
In [24]: queue = sqs.get_queue_by_name(QueueName='MyQueue')
In [25]: messages = queue.receive_messages(MaxNumberOfMessages=5, WaitTimeSeconds=10)
In [26]: len(messages)
Out[26]: 1

有什么想法吗?

嗯,根据文档:

If the number of messages in the queue is small (fewer than 1,000), you most likely get fewer messages than you requested per ReceiveMessage call