mhart / kinesalite

An implementation of Amazon's Kinesis built on LevelDB
MIT License
810 stars 86 forks source link

Inaccessible host localhost error when calling the createStream method and using NodeJS 16 #121

Open nou2003 opened 1 year ago

nou2003 commented 1 year ago

I'm getting the below error when calling the createStream method and using NodeJS 16. The same code is working on NodeJS 14. The code below is used in a unit test with mocha

### This is the error

Kinesalite started on port 14567 UnknownEndpoint: Inaccessible host: localhost'. This service may not be available in theus-east-1' region. at Request.ENOTFOUND_ERROR

### This is the code throw error

const localKinesis = require('local_kinesis');

const setupKinesis = async () => { kinesis = kinesis || await localKinesis.start(); try { stream = stream || await kinesis.createStream({ ShardCount: 1, StreamName: streamName }).promise(); } catch (e) { console.log(e.stack); console.log(e.name); console.log(e.message); console.log('Stream already exists, skipping'); } };

### local_kinesis is defined as

const AWS = require('aws-sdk'); const kinesalite = require('kinesalite'); const kinesisLocalPort = 14567;

const startKinesis = async (kinesaliteServer) => { kinesaliteServer.listen(kinesisLocalPort, (err) => { if (err) throw err; console.log(Kinesalite started on port ${kinesisLocalPort}); }); };

const start = async () => { // Returns a standard Node.js HTTP server const kinesaliteServer = kinesalite({ path: './kinesisTemp', createStreamMs: 0 });

const kinesis = new AWS.Kinesis({ endpoint: http://localhost:${kinesisLocalPort}, region: 'us-east-1' }); await startKinesis(kinesaliteServer); kinesis._server = kinesaliteServer; return kinesis; };

const stop = async (kinesis) => { kinesis._server.close(); };

module.exports = { start, stop };