title: AWS SDK and NODE JS --> UnknownEndpoint
body: <p>I have followed this guide: <a href="https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/ec2-example-creating-an-instance.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/ec2-example-creating-an-instance.html</a></p>
  
  <p>When I run the code below - I get the UnknowEndPoint error.</p>
  
  <ol>
  <li><p>I have created an AWS IAM user and added the user to a group with the policy name "IAMFullAccess" - I don't know which other policy would fit (I can see in the AWS dashboard that my credentials has been used programmatically - So I guess this part works well...)?</p></li>
  <li><p>I have placed my credentials in the .aws folder in a file named credentials.</p></li>
  <li><p>I am not sure what actually to put inside the 'KeyName' below - currently I have entered the Key Pair Name I find by clicking on one of my existing AWS EC2 instances in the dashboard. Is this correct?</p></li>
  </ol>
  
  <p>Is there some security group or similar I need to edit - to able to connect NodeJS to my AWS account? Otherwise I have no clue what to do?</p>
  
  <p>In start.js file:</p>
  
  <pre><code>process.env.AWS_SDK_LOAD_CONFIG=1;    
  var AWS_SDK = require('./aws_sdk');
  var aws_sdk = new AWS_SDK();
  
  aws_sdk.CopyInstance();
  </code></pre>
  
  <p>In aws_sdk.js file:</p>
  
  <pre><code>function AWS_SDK() {
  
      this.CopyInstance = function() {
  
          try {
  
              // Load the AWS SDK for Node.js
              var AWS = require('aws-sdk');
  
              //Set the region
              AWS.config.update({region: 'us-east-2a'});
  
              var instanceParams = {
                  ImageId: 'ami-0...',
                  InstanceType: 't1.micro',
                  KeyName: '&lt;Key_name&gt;',
                  MinCount: 1,
                  MaxCount: 1
              };
  
              // Create a promise on an EC2 service object
              var instancePromise = new AWS.EC2({apiVersion: '2016-11-15'}).runInstances(instanceParams).promise();
  
              // Handle promise's fulfilled/rejected states
              instancePromise.then(
                  function (data) {
                      console.log(data);
                      var instanceId = data.Instances[0].InstanceId;
                      console.log("Created instance", instanceId);
                      // Add tags to the instance
                      var tagParams = {
                          Resources: [instanceId], Tags: [
                              {
                                  Key: 'Name',
                                  Value: 'SDK Sample'
                              }
                          ]
                      };
  
                      // Create a promise on an EC2 service object
                      var tagPromise = new AWS.EC2({apiVersion: '2016-11-15'}).createTags(tagParams).promise();
                      // Handle promise's fulfilled/rejected states
                      tagPromise.then(
                          function (data) {
                              console.log("Instance tagged");
                          }).catch(
                          function (err) {
                              console.error(err, err.stack);
                          });
                  }).catch(
                  function (err) {
                      console.error(err, err.stack);
                  });
          }
          catch(e){
              wl.info('Error: ' + e);
          }
      } 
  
  function create() {
  
      if(globalAWS === null)
          globalAWS = new AWS_SDK();
  
      return globalAWS;
  }
  
  module.exports = create;
  </code></pre>
  
  <p>ERROR:</p>
  
  <blockquote>
    <p>{ UnknownEndpoint: Inaccessible host: <code>ec2.us-east-2a.amazonaws.com'.
    This service may not be available in the</code>us-east-2a' region.
        at Request.ENOTFOUND_ERROR (D:\Workspace\BitBucket\Test\node_modules\aws-sdk\lib\event_listeners.js:486:46)
        at Request.callListeners (D:\Workspace\BitBucket\Test\node_modules\aws-sdk\lib\sequential_executor.js:106:20)
        at Request.emit (D:\Workspace\BitBucket\Test\node_modules\aws-sdk\lib\sequential_executor.js:78:10)
        at Request.emit (D:\Workspace\BitBucket\Test\node_modules\aws-sdk\lib\request.js:683:14)
        at ClientRequest.error (D:\Workspace\BitBucket\Test\node_modules\aws-sdk\lib\event_listeners.js:325:22)
        at ClientRequest. (D:\Workspace\BitBucket\Test\node_modules\aws-sdk\lib\http\node.js:93:19)
        at ClientRequest.emit (events.js:182:13)
        at ClientRequest.EventEmitter.emit (domain.js:442:20)
        at TLSSocket.socketErrorListener (_http_client.js:391:9)
        at TLSSocket.emit (events.js:182:13)   message:    'Inaccessible host: <code>ec2.us-east-2a.amazonaws.com\'. This service may not be
    available in the</code>us-east-2a\' region.',   code: 'UnknownEndpoint',<br>
    region: 'us-east-2a',   hostname: 'ec2.us-east-2a.amazonaws.com',<br>
    retryable: true,   originalError:    { Error: getaddrinfo ENOTFOUND
    ec2.us-east-2a.amazonaws.com ec2.us-east-2a.amazonaws.com:443
           at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:57:26)
         message:
          'getaddrinfo ENOTFOUND ec2.us-east-2a.amazonaws.com ec2.us-east-2a.amazonaws.com:443',
         errno: 'ENOTFOUND',
         code: 'NetworkingError',
         syscall: 'getaddrinfo',
         hostname: 'ec2.us-east-2a.amazonaws.com',
         host: 'ec2.us-east-2a.amazonaws.com',
         port: 443,
         region: 'us-east-2a',
         retryable: true,
         time: 2019-01-14T20:03:42.177Z },   time: 2019-01-14T20:03:42.177Z } 'UnknownEndpoint: Inaccessible host:
    <code>ec2.us-east-2a.amazonaws.com\'. This service may not be available in
    the</code>us-east-2a\' region.\n    at Request.ENOTFOUND_ERROR
    (D:\Workspace\BitBucket\Test\node_modules\aws-sdk\lib\event_listeners.js:486:46)\n
    at Request.callListeners
    (D:\Workspace\BitBucket\Test\node_modules\aws-sdk\lib\sequential_executor.js:106:20)\n
    at Request.emit
    (D:\Workspace\BitBucket\Test\node_modules\aws-sdk\lib\sequential_executor.js:78:10)\n
    at Request.emit
    (D:\Workspace\BitBucket\Test\node_modules\aws-sdk\lib\request.js:683:14)\n
    at ClientRequest.error
    (D:\Workspace\BitBucket\Test\node_modules\aws-sdk\lib\event_listeners.js:325:22)\n
    at ClientRequest.
    (D:\Workspace\BitBucket\Test\node_modules\aws-sdk\lib\http\node.js:93:19)\n
    at ClientRequest.emit (events.js:182:13)\n    at
    ClientRequest.EventEmitter.emit (domain.js:442:20)\n    at
    TLSSocket.socketErrorListener (_http_client.js:391:9)\n    at
    TLSSocket.emit (events.js:182:13)'</p>
    
    <p>Process finished with exit code 0</p>
  </blockquote>
  
  <p>If I change the REGION to "us-east-2" (delete the 'a' at the end) the error changes to this:</p>
  
  <pre><code>{ Unsupported: The requested configuration is currently not supported. Please check the documentation for supported configurations.
      at Request.extractError (D:\Workspace\BitBucket\Test\node_modules\aws-sdk\lib\services\ec2.js:50:35)
      at Request.callListeners (D:\Workspace\BitBucket\Test\node_modules\aws-sdk\lib\sequential_executor.js:106:20)
      at Request.emit (D:\Workspace\BitBucket\Test\node_modules\aws-sdk\lib\sequential_executor.js:78:10)
      at Request.emit (D:\Workspace\BitBucket\Test\node_modules\aws-sdk\lib\request.js:683:14)
      at Request.transition (D:\Workspace\BitBucket\Test\node_modules\aws-sdk\lib\request.js:22:10)
      at AcceptorStateMachine.runTo (D:\Workspace\BitBucket\Test\node_modules\aws-sdk\lib\state_machine.js:14:12)
      at D:\Workspace\BitBucket\Test\node_modules\aws-sdk\lib\state_machine.js:26:10
      at Request.&lt;anonymous&gt; (D:\Workspace\BitBucket\Test\node_modules\aws-sdk\lib\request.js:38:9)
      at Request.&lt;anonymous&gt; (D:\Workspace\BitBucket\Test\node_modules\aws-sdk\lib\request.js:685:12)
      at Request.callListeners (D:\Workspace\BitBucket\Test\node_modules\aws-sdk\lib\sequential_executor.js:116:18)
    message:
     'The requested configuration is currently not supported. Please check the documentation for supported configurations.',
    code: 'Unsupported',
    time: 2019-01-14T20:31:55.954Z,
    requestId: '815a44e2-5d0d-453e-a4ff-6faac2695064',
    statusCode: 400,
    retryable: false,
    retryDelay: 51.269952198296934 } 'Unsupported: The requested configuration is currently not supported. Please check the documentation for supported configurations.\n    at Request.extractError (D:\\Workspace\\BitBucket\\Test\\node_modules\\aws-sdk\\lib\\services\\ec2.js:50:35)\n    at Request.callListeners (D:\\Workspace\\BitBucket\\Test\\node_modules\\aws-sdk\\lib\\sequential_executor.js:106:20)\n    at Request.emit (D:\\Workspace\\BitBucket\\Test\\node_modules\\aws-sdk\\lib\\sequential_executor.js:78:10)\n    at Request.emit (D:\\Workspace\\BitBucket\\Test\\node_modules\\aws-sdk\\lib\\request.js:683:14)\n    at Request.transition (D:\\Workspace\\BitBucket\\Test\\node_modules\\aws-sdk\\lib\\request.js:22:10)\n    at AcceptorStateMachine.runTo (D:\\Workspace\\BitBucket\\Test\\node_modules\\aws-sdk\\lib\\state_machine.js:14:12)\n    at D:\\Workspace\\BitBucket\\Test\\node_modules\\aws-sdk\\lib\\state_machine.js:26:10\n    at Request.&lt;anonymous&gt; (D:\\Workspace\\BitBucket\\Test\\node_modules\\aws-sdk\\lib\\request.js:38:9)\n    at Request.&lt;anonymous&gt; (D:\\Workspace\\BitBucket\\Test\\node_modules\\aws-sdk\\lib\\request.js:685:12)\n    at Request.callListeners (D:\\Workspace\\BitBucket\\Test\\node_modules\\aws-sdk\\lib\\sequential_executor.js:116:18)'
  </code></pre>
  
  <p>Update 1:</p>
  
  <p>I changed the REGION from to 'us-est-2' and now also updated my ~/.aws/config file (before the file only contained 1 line/row: 'region=us-west-2'):</p>
  
  <pre><code>[default]
  region=us-west-2
  output=json
  </code></pre>
  
  <p>Now I get this error (when I try to decode it in the CMD) - I still don't understand what extra roles I have to give/grant my IAM-AWS user to be able read the error message?</p>
  
  <pre><code>An error occurred (AccessDenied) when calling the DecodeAuthorizationMessage operation: User: arn:aws:iam::0046xxxxxxx:user/user_name is not authorized to perform: sts:DecodeAuthorizationMessage
  </code></pre>