aws sdk sqs既不发送消息也不显示错误但永远卡住

aws sdk sqs neither sending message or showing errors but stuck forever

我正在尝试使用 aws sdk 来测试 goaws 但我的以下程序永远挂起。谁能解释一下我在这里做错了什么?

var AWS = require('aws-sdk');
var endpoint = new AWS.Endpoint('http://localhost:4100')
AWS.config.update({region: 'us-east-1'}, {endpoint});

// Create an SQS service object
var sqs =  new AWS.SQS({apiVersion: '2012-11-05'});

var params = {
    DelaySeconds: 10,
    MessageAttributes: {
        "Name": {
            DataType: "String",
            StringValue: "AAAA"
        },
        "SurName": {
            DataType: "String",
            StringValue: "BBBB"
        }
    },
    MessageBody: "whats up",
    QueueUrl: "http://us-east-1.goaws.com:4100/100010001000/local-queue1"
};

sqs.sendMessage(params, function(err, data) {
    if (err) {
        console.log("Error", err);
    } else {
        console.log("Success", data.MessageId);
    }
});

sqs 队列 URL 我尝试使用 AWS cli 进行测试,它确实有效。所以我不明白程序有什么问题。

aws sqs send-message --region us-east-1 --endpoint-url http://localhost:4100 --queue-url http://us-east-1.goaws.com:4100/100010001000/local-queue1 --message-body "Hello from Amazon SQS."
{
  "MD5OfMessageBody": "c5dba0dd8f89fe763f66cbddb9c37cb7",
  "MD5OfMessageAttributes": "",
  "MessageId": "f5a8ce0d-983f-4fb5-b517-153d2c56c08b",
  "SequenceNumber": ""
}

我不知道你的 config 更新如何工作。首先,我不认为端点是 global Config object. Also, it isn't set as an attribute in the dictionary, which should both the in the object that is the first argument. Next, I think you QueueUrl should be http://localhost:4100/100010001000/local-queue1. I believe that endpoint should be configured in the constructor for the SQS resource.

上的属性

这是一些我没有测试过的更新代码,但我认为它可以工作。

var AWS = require('aws-sdk');
var endpoint = new AWS.Endpoint('http://localhost:4100')
AWS.config.update({region: 'us-east-1'});

// Create an SQS service object
var sqs =  new AWS.SQS({
    apiVersion: '2012-11-05',
    endpoint: endpoint
});

var params = {
    DelaySeconds: 10,
    MessageAttributes: {
        "Name": {
            DataType: "String",
            StringValue: "AAAA"
        },
        "SurName": {
            DataType: "String",
            StringValue: "BBBB"
        }
    },
    MessageBody: "whats up",
    QueueUrl: "http://localhost:4100/100010001000/local-queue1"
};

sqs.sendMessage(params, function(err, data) {
    if (err) {
        console.log("Error", err);
    } else {
        console.log("Success", data.MessageId);
    }
});

此外,我认为来自 goaws 的日志会有所帮助。