title: AWS Credentials error: could not load credentials from any providers. ElasticSearch Service node.js
body: <p>I was having a problem that I think should be posted on the internet. I may not know the internal issue, but I think I have a solution. Anyway the problem:</p>
  
  <p>I'm hosting an ElasticSearch Service on AWS, and I'm trying to access that service locally and or through my ec2 service hosted on AWS. </p>
  
  <p>But when I try to locally I get this error: <code>Request Timeout after 30000ms</code></p>
  
  <p>When I try it on my ec2 I get this error: <code>AWS Credentials error: Could not load credentials from any providers</code></p>
  
  <p>Here was how I set up the credentials and made the query:</p>
  
  <pre><code>const AWS = require('aws-sdk');
  const connectionClass = require('http-aws-es');
  const elasticsearch = require('elasticsearch');
  
  try {
      var elasticClient = new elasticsearch.Client({
          host: "https://some-elastic.us-east-1.es.amazonaws.com/",
          log: 'error',
          connectionClass: connectionClass,
          amazonES: {
              region: 'us-east-1',
              credentials: new AWS.Credentials('id', 'key')
          }
      });
  
      elasticClient.indices.delete({
          index: 'foo',
      }).then(function (resp) {
          console.log("Successful query!");
          console.log(JSON.stringify(resp, null, 4));
      }, function (err) {
          console.trace(err.message);
      });
  } catch (err) {
      console.log(err);
  } finally {
  }
  </code></pre>
  
  <p>So as stated I kept getting this error. I tried many other variations to pass the credentials.</p>