boto3 sqs 在未指定端点时不正确 url url

boto3 sqs incorrect url when not specified endpoint url

创建 boto3 客户端时是否总是需要指定 endpoint_url? 为什么我不能指定 QueueUrl 作为方法参数?

# boto3==1.16.51
import boto3


client = boto3.client('sqs')

messages = client.receive_message(
    QueueUrl='https://sqs.eu-central-1.amazonaws.com/325672072888/event-queue-test',
    WaitTimeSeconds=2,
    MaxNumberOfMessages=1,
    AttributeNames=["All"],
)

异常:

botocore.exceptions.ClientError: An error occurred (InvalidAddress) when calling the ReceiveMessage operation: The address https://eu-central-1.queue.amazonaws.com/ is not valid for this endpoint.

似乎它采用 sqs 队列的默认值。但为什么它不从 QueueUrl

中获取价值

错误消息中的 url 与 QueueUrl 不同,因为 AWS CLI 和 boto3 使用 legacy endpoint,其中之一是 eu-central-1.queue.amazonaws.com.来自 docs:

If you use the AWS CLI or SDK for Python, you can use the following legacy endpoints.

您可以使用以下方式检查:

print(client._endpoint)