title: AWS Elastic Beanstalk Worker Can't Connect to SQS
body: <p>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. </p>
  
  <p>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.</p>
  
  <pre class="lang-js prettyprint-override"><code>    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);
              });
          }
      });
  </code></pre>
  
  <p>My IAM Policy for the worker</p>
  
  <pre><code>    {
          "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": "*"
              }
          ]
      }
  </code></pre>
  
  <p>For queue, I set the permission to allow everybody to access it. I give it a name <strong>testingqueue</strong></p>
  
  <p><img src="https://i.stack.imgur.com/zmQTX.jpg" alt="enter image description here"></p>
  
  <p>For worker configuration</p>
  
  <p><img src="https://i.stack.imgur.com/Fs93l.jpg" alt="enter image description here"></p>
  
  <p>I checked the log <strong>/var/log/nodejs/nodejs.log</strong></p>
  
  <pre><code>^[[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 
  </code></pre>
  
  <p>I also checked the awssqsd log <strong>/var/log/aws-sqsd/default.log</strong></p>
  
  <pre><code>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
  </code></pre>
  
  <p>I keep getting error 400. I'm curious why it can't connect.</p>
  
  <p>Things I have done: </p>
  
  <ol>
  <li>Queue is created and selected in worker configuration </li>
  <li>Worker already use correct IAM policy </li>
  <li>The HTTP Path is match, using <strong>/hello</strong> with POST method</li>
  </ol>
  
  <p>Anyone maybe can help me here</p>
  
  <p>Thank you</p>