title: UnknownEndpoint: Inaccessible host: `localhost'. When trying to connect to localhost with express and dynamodb local
body: <p>I am using docker compose to create two containers one for dynamodb local and one for nodejs express app.</p>
  <p><strong>docker-compose.dev.yml</strong></p>
  <pre><code>version: '3'
  
  services:
    dynamodb-local:
      command: &quot;-jar DynamoDBLocal.jar -sharedDb -optimizeDbBeforeStartup -dbPath ./data&quot;
      image: &quot;amazon/dynamodb-local:latest&quot;
      container_name: dynamodb-local
      ports:
        - &quot;8000:8000&quot;
      volumes:
        - &quot;./docker/dynamodb:/home/dynamodblocal/data&quot;
      working_dir: /home/dynamodblocal
      networks:
        - dynamodb-network
  
    node-app:
      depends_on:
          - dynamodb-local
      container_name: dev-nodejs-backend
      ports:
        - '3000:3000'
      volumes:
        - .:/usr/src/node-app
      environment:
        AWS_ACCESS_KEY_ID: 'DUMMYIDEXAMPLE'
        AWS_SECRET_ACCESS_KEY: 'DUMMYEXAMPLEKEY'
      networks:
        - dynamodb-network
      command: yarn dev -L
  
  networks:
    dynamodb-network:
      driver: bridge
  </code></pre>
  <p><strong>Dockerfile</strong></p>
  <pre><code>FROM node:alpine
  
  RUN mkdir -p /usr/src/node-app &amp;&amp; chown -R node:node /usr/src/node-app
  
  WORKDIR /usr/src/node-app
  
  COPY package.json yarn.lock ./
  
  USER node
  
  RUN yarn install --pure-lockfile
  
  COPY --chown=node:node . .
  
  EXPOSE 3000
  
  </code></pre>
  <p><strong>model.js</strong></p>
  <pre><code>var AWS = require('aws-sdk');
  
  AWS.config.update({
    accessKeyId: 'YOUR-ACCESSKEYID' ,
    secretAccessKey: 'YOUR-SECRETACCESSKEY' ,
    region: &quot;localhost&quot;,
    endpoint: 'http://localhost:8000',
  });
  
  const DynamoDB = new AWS.DynamoDB();
  var docClient = new AWS.DynamoDB.DocumentClient();
  
  var table = 'URL';
  
  const createTable = async () =&gt; {
    var params = {
      TableName : table,
      KeySchema: [
          { AttributeName: &quot;hash&quot;, KeyType: &quot;HASH&quot;},  //Partition key
      ],
      AttributeDefinitions: [       
          { AttributeName: &quot;hash&quot;, AttributeType: &quot;S&quot; },
      ],
      ProvisionedThroughput: {      
          ReadCapacityUnits: 5, 
          WriteCapacityUnits: 5
      }
  };
    const result = await DynamoDB.createTable(params).promise();
    return result;
  }
  </code></pre>
  <p>The error on console</p>
  <pre><code>UnknownEndpoint: Inaccessible host: `localhost'. This service may not be available in the `localhost' region.
  at Request.ENOTFOUND_ERROR (/usr/src/node-app/node_modules/aws-sdk/lib/event_listeners.js:507:46)
  at Request.callListeners (/usr/src/node-app/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
  at Request.emit (/usr/src/node-app/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
  at Request.emit (/usr/src/node-app/node_modules/aws-sdk/lib/request.js:688:14)
  at ClientRequest.error (/usr/src/node-app/node_modules/aws-sdk/lib/event_listeners.js:339:22)
  at ClientRequest.&lt;anonymous&gt; (/usr/src/node-app/node_modules/aws-sdk/lib/http/node.js:96:19)
  at ClientRequest.emit (node:events:379:20)
  at ClientRequest.EventEmitter.emit (node:domain:470:12)
  at Socket.socketErrorListener (node:_http_client:462:9)
  at Socket.emit (node:events:379:20)
  at Socket.EventEmitter.emit (node:domain:470:12)
  at emitErrorNT (node:internal/streams/destroy:188:8)
  at emitErrorCloseNT (node:internal/streams/destroy:153:3)
  at processTicksAndRejections (node:internal/process/task_queues:81:21) {
  code: 'UnknownEndpoint',
  region: 'localhost',
  hostname: 'localhost',
  retryable: true,
  originalError: Error: connect ECONNREFUSED 127.0.0.1:8000
  at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1139:16) {
  errno: -111,
  code: 'NetworkingError',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 8000,
  region: 'localhost',
  hostname: 'localhost',
  retryable: true,
  time: 2021-02-05T14:23:15.559Z
  },
  time: 2021-02-05T14:23:15.559Z
  }
  </code></pre>
  <p>Dynamodb local is running on port 8000, but I am unable to connect it from my express app.
  Is there anything I can change in compose file or it is some different error?</p>