AWS SQS 异常“413 请求实体太大”

Usm*_*man 3 amazon-sqs laravel laravel-excel aws-lambda laravel-vapor

我已经被困了一段时间来弄清楚以下异常,任何帮助都会被分配。我们正在 Laravel 项目上使用 AWS Lambda 服务。我们正在使用Laravel Excel将大量数据导出到 CSV 文件,并通过 Laravel SQS 队列来完成此操作。

PHP 版本:7.2
Laravel 框架:7.30.1
Laravel Excel:3.1

例外:

Aws\Sqs\Exception\SqsException /tmp/vendor/aws/aws-sdk-php...
stage.ERROR: Error executing "SendMessage" on "https://sqs.eu-central- 
1.amazonaws.com"; AWS HTTP error: Client error: `POST https://sqs.eu- 
central-1.amazonaws.com/` resulted in a `413 Request Entity Too Large` 
response:
HTTP content length exceeded 1662976 bytes.
Unable to parse error information from response - Error parsing XML: String could not be parsed as 
XML {"exception":"[object] (Aws\\Sqs\\Exception\\SqsException(code: 0): Error executing      
\"SendMessage\" on \"https://sqs.eu-central-1.amazonaws.com/"; AWS 
HTTP error: Client error: `POST https://sqs.eu-central-1.amazonaws.com/` resulted in a `413 Request Entity Too Large` response:
HTTP content length exceeded 1662976 bytes.
Unable to parse error information from response - Error parsing XML: String could not be parsed as 
XML at /tmp/vendor/aws/aws-sdk-php/src/WrappedHttpHandler.php:195)
[stacktrace]
Run Code Online (Sandbox Code Playgroud)

Mau*_*ice 6

来自文档

消息大小
最小消息大小为 1 字节(1 个字符)。最大值为 262,144 字节 (256 KB)。

我的猜测是您尝试发送的文件大于256KB,这是 AWS 中 SQS 消息的硬限制。

输出HTTP content length exceeded 1662976 bytes表明我的猜测可能是正确的。

这种情况下的常见模式是将文件上传到 S3 并通过队列发送对对象的引用。