2
votes

I have a problem with AWS ElasticBeanstalk Worker with SQS. I have read many resources and do experiment about it but still can't connect the worker with SQS successfully.

The worker act as consumer is created using Node.js with Hapi. I have tested this script using CURL in my local computer and it works well.

    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);
            });
        }
    });

My IAM Policy for the worker

    {
        "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": "*"
            }
        ]
    }

For queue, I set the permission to allow everybody to access it. I give it a name testingqueue

enter image description here

For worker configuration

enter image description here

I checked the log /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 

I also checked the awssqsd log /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

I keep getting error 400. I'm curious why it can't connect.

Things I have done:

  1. Queue is created and selected in worker configuration
  2. Worker already use correct IAM policy
  3. The HTTP Path is match, using /hello with POST method

Anyone maybe can help me here

Thank you

1

1 Answers

0
votes

there is nothing wrong with your code. I just depoyed it to AWS with no problem.


/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]

As you can see my test message was received. Only difference is can see is thah i have autogenerated queue, but that should not be a problem, because your logs shows that demon took message from queue and forwarded it. I use the same policy as you do for my worker.