在node.js中使用@aws-sdk/client-sqs时出现错误

问题描述 投票:0回答:1

使用SQS的

sendMessage
方法时出现以下错误
error SyntaxError: Unexpected token T in JSON at position 0 Deserialization error: to see the raw response, inspect the hidden field {error}.$response on this object. at JSON.parse (<anonymous>) at /var/www/html/apachedev/git/repo/node_modules/@aws-sdk/client-sqs/dist-cjs/protocols/Aws_json1_0.js:1981:21

错误来自 Aws_json1_0.js 的以下部分 这里

encoded
变量具有这个值
There was an internal server error.

const parseBody = (streamBody, context) => collectBodyString(streamBody, context).then((encoded) => {
    if (encoded.length) {
        console.log(encoded);
        return JSON.parse(encoded);
    }
    return {};
});

代码片段:

import { SQS } from "@aws-sdk/client-sqs";
async enqueueMessage(message: NewMessage): Promise<QueuedMessage> {    
    console.log(message, MESSAGE_QUEUE_URL);
    const result = await this.sqsClient
      .sendMessage({
        QueueUrl: MESSAGE_QUEUE_URL,
        MessageBody: JSON.stringify(message),
      });
    console.log("RESULT", result);
    return {
      id: result.MessageId || '',
      ...message,
    };
  }

在上面的代码片段中,消息和队列 URL 看起来是正确的。

消息价值:

{
  user_id: '68057407',
  queued_by: '[email protected]',
  action: 'download',
  filters: {},
  report_id: 10,
  title: 'Title',
  download_id: 3722
}

MESSAGE_QUEUE_URL 的值:http://localhost:9324/queue/jobQueue

版本: "@aws-sdk/client-sqs": "^3.431.0" Node.js:v18.18.1

尝试使用sendMessage方法,但没有将消息添加到队列中。

node.js aws-sdk amazon-sqs aws-sdk-nodejs
1个回答
0
投票

您使用Localstack吗?我看到

MESSAGE_QUEUE_URL
指向
http://localhost:9324
。如果是,您可能需要提取昨天(11/23/23)的最新镜像

AWS SDK 最近发生了变化,其中默认使用 AWS JSON 协议。但是,Localstack 需要 AWS 查询协议格式。

https://github.com/localstack/localstack/issues/8267#issuecomment-1803663216

© www.soinside.com 2019 - 2024. All rights reserved.