【问题标题】:AWS Elastic Beanstalk Worker Can't Connect to SQSAWS Elastic Beanstalk Worker 无法连接到 SQS
【发布时间】:2015-09-18 09:56:48
【问题描述】:

我在使用带有 SQS 的 AWS ElasticBeanstalk Worker 时遇到问题。我已经阅读了很多资源并对其进行了实验,但仍然无法成功地将工作人员与 SQS 连接起来。

作为消费者的工作者是使用带有 Hapi 的 Node.js 创建的。我已经在本地计算机上使用 CURL 测试了这个脚本,它运行良好。

    var Hapi = require('hapi');
    var Good = require('good');

    var server = new Hapi.Server();
    server.connection({
        port: process.env.PORT || 3000
    });

    server.route({
      method: 'POST',
      path: '/hello',
      handler: function (request, reply) {

        console.log('CIHUUY response: ', request.payload);

        reply();
      }
    });

    server.register({
        register: require('good'),
        options: {
          reporters: [{
              reporter: require('good-console'),
              events: { log: '*', response: '*' }
          }]
        }
    }, function (err) {

        if (err) {
            console.error(err);
        }
        else {
            server.start(function () {

                console.info('Server started at ' + server.info.uri);
            });
        }
    });

我的工作人员 IAM 政策

    {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Sid": "QueueAccess",
                "Action": [
                    "sqs:ChangeMessageVisibility",
                    "sqs:DeleteMessage",
                    "sqs:ReceiveMessage",
                    "sqs:SendMessage"
                ],
                "Effect": "Allow",
                "Resource": "*"
            },
            {
                "Sid": "MetricsAccess",
                "Action": [
                    "cloudwatch:PutMetricData"
                ],
                "Effect": "Allow",
                "Resource": "*"
            }
        ]
    }

对于队列,我设置了允许所有人访问它的权限。我给它起一个名字testingqueue

用于工作人员配置

我检查了日志/var/log/nodejs/nodejs.log

^[[1;33mpost^[[0m /hello {} ^[[33m400^[[0m (2ms)
150701/094208.444, [response], http://ip-10-142-107-58:8081: ^[[1;33mpost^[[0m /hello {} ^[[33m400^[[0m (1ms)
150701/094208.773, [response], http://ip-10-142-107-58:8081: ^[[1;33mpost^[[0m /hello {} ^[[33m400^[[0m (2ms)
150701/094208.792, [response], http://ip-10-142-107-58:8081: ^[[1;33mpost^[[0m /hello {} ^[[33m400^[[0m (1ms)
150701/094208.882, [response], http://ip-10-142-107-58:8081: ^[[1;33mpost^[[0m /hello {} ^[[33m400^[[0m (1ms)
150701/094208.951, [response], http://ip-10-142-107-58:8081: ^[[1;33mpost^[[0m 

我还检查了 awssqsd 日志 /var/log/aws-sqsd/default.log

2015-07-01T09:44:40Z http-err: 75704523-42de-40de-9f9f-8a59eb3fb332 (7324) 400 - 0.004
2015-07-01T09:44:40Z message: sent to %[http://localhost:80]
2015-07-01T09:44:40Z http-err: 59e2a75b-87f7-4833-8cde-11900d48a7c5 (3770) 400 - 0.007
2015-07-01T09:44:40Z message: sent to %[http://localhost:80]
2015-07-01T09:44:40Z http-err: e2acb4e0-1059-4dc7-9101-8d3e4c974108 (7035) 400 - 0.003
2015-07-01T09:44:40Z message: sent to %[http://localhost:80]
2015-07-01T09:44:40Z http-err: 04d2436a-0b1e-4a1f-8826-a2b30710f569 (9957) 400 - 0.005

我不断收到错误 400。我很好奇为什么它无法连接。

我做过的事情:

  1. 在工作配置中创建和选择队列
  2. 工作人员已使用正确的 IAM 策略
  3. HTTP 路径匹配,使用 /hello 和 POST 方法

任何人都可以在这里帮助我

谢谢

【问题讨论】:

    标签: amazon-web-services amazon-elastic-beanstalk amazon-sqs worker


    【解决方案1】:

    您的代码没有任何问题。我只是将它部署到 AWS 上没有问题。


    /var/log/nodejs/nodejs.log

    Server started at http://myIP:8081
    CIHUUY response:  { test: 'testvalue' }
    151118/110150.862, [response], http://myIP:8081: [1;33mpost[0m /hello {} [32m200[0m (38ms) 
    

    /var/log/aws-sqsd/default.log

    2015-11-18T10:58:38Z init: initializing aws-sqsd 2.0 (2015-02-18)
    2015-11-18T10:58:39Z start: polling https://sqs.us-west-2.amazonaws.com/myaccountname/awseb-e-mnpfjxiump-stack-AWSEBWorkerQueue-1FPDK4Z8E3WRX
    2015-11-18T11:01:50Z message: sent to %[http://localhost:80]
    

    如您所见,我的测试消息已收到。唯一的区别是可以看到我有自动生成的队列,但这应该不是问题,因为您的日志显示恶魔从队列中获取消息并转发它。我使用与您对我的工人相同的政策。

    【讨论】:

      猜你喜欢
      • 2017-10-01
      • 1970-01-01
      • 2021-10-07
      • 2018-12-13
      • 2014-07-07
      • 2016-08-24
      • 2015-04-13
      • 2018-09-07
      • 2014-09-12
      相关资源
      最近更新 更多