AWS Elastic Beanstalk Worker无法连接到SQS。

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

我有一个AWS ElasticBeanstalk Worker与SQS的问题。我看了很多资料,也做了很多实验,但还是不能成功连接Worker和SQS。

Worker作为消费者是用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);
            });
        }
    });

我的Worker的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": "*"
            }
        ]
    }

对于队列,我把权限设置为允许所有人访问。我给它取了一个名字 测试队列

enter image description here

对于工人配置

enter image description here

我查了日志 varlognodejsnodejs.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日志。varlogaws-sqsddefault.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路径是匹配的,使用 你好 用POST方法

有谁能帮我?

谢谢你了

amazon-web-services amazon-elastic-beanstalk amazon-sqs worker
1个回答
0
投票

你的代码没什么问题。我刚刚把它部署到AWS上,没有问题。


varlognodejsnodejs.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) 

varlogaws-sqsddefault.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]

正如你所看到的,我的测试信息已经收到了,唯一不同的是我有一个自动生成的队列,但应该没有问题,因为你的日志显示恶魔从队列中获取了信息并转发。唯一不同的是,我有自动生成的队列,但这应该不是问题,因为你的日志显示恶魔从队列中获取了消息并转发了它。我对我的工人使用了和你一样的策略。

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