Trouble Connecting To DynamoDB Locally with ECONNREFUSED - node.js

I'm attempting to save form submissions to a DynamoDB table, however, I'm running into issues connecting locally. I'm running DynamoDB locally for now, but I would later like to move it back to a normal DDB instance accessible from Elastic Beanstalk.
I've downloaded and unzipped dynamodb-local into a directory and ran the java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb
command, ensuring that I'm in the appropriate directory. When I run the command I get this:
Initializing DynamoDB Local with the following configuration:
Port: 8000
InMemory: false
DbPath: null
SharedDb: true
shouldDelayTransientStatuses: false
CorsParams: *
At this point I attempt to submit a form to my POST endpoint in app.js, but I get this repeating error in the terminal I'm running DynamoDB local in:
Jan 12, 2019 1:24:25 PM com.almworks.sqlite4java.Internal log
WARNING: [sqlite] cannot open DB[1]:
com.almworks.sqlite4java.SQLiteException: [-91] cannot load library: java.lang.UnsatisfiedLinkError: C:\cygwin64\home\Administrator\dynamodb_local_latest\DynamoDBLocal_lib\sqlite4java-win32-x64.dll: Access is denied
Jan 12, 2019 1:24:25 PM com.almworks.sqlite4java.Internal log
SEVERE: [sqlite] SQLiteQueue[shared-local-instance.db]: error running job queue
com.almworks.sqlite4java.SQLiteException: [-91] cannot load library: java.lang.UnsatisfiedLinkError: C:\cygwin64\home\Administrator\dynamodb_local_latest\DynamoDBLocal_lib\sqlite4java-win32-x64.dll: Access is denied
at com.almworks.sqlite4java.SQLite.loadLibrary(SQLite.java:97)
at com.almworks.sqlite4java.SQLiteConnection.open0(SQLiteConnection.java:1441)
at com.almworks.sqlite4java.SQLiteConnection.open(SQLiteConnection.java:282)
at com.almworks.sqlite4java.SQLiteConnection.open(SQLiteConnection.java:293)
at com.almworks.sqlite4java.SQLiteQueue.openConnection(SQLiteQueue.java:464)
at com.almworks.sqlite4java.SQLiteQueue.queueFunction(SQLiteQueue.java:641)
at com.almworks.sqlite4java.SQLiteQueue.runQueue(SQLiteQueue.java:623)
at com.almworks.sqlite4java.SQLiteQueue.access$000(SQLiteQueue.java:77)
at com.almworks.sqlite4java.SQLiteQueue$1.run(SQLiteQueue.java:205)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.UnsatisfiedLinkError: C:\cygwin64\home\Administrator\dynamodb_local_latest\DynamoDBLocal_lib\sqlite4java-win32-x64.dll: Access is denied
at java.base/java.lang.ClassLoader$NativeLibrary.load0(Native Method)
at java.base/java.lang.ClassLoader$NativeLibrary.load(Unknown Source)
at java.base/java.lang.ClassLoader$NativeLibrary.loadLibrary(Unknown Source)
at java.base/java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.base/java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.base/java.lang.Runtime.load0(Unknown Source)
at java.base/java.lang.System.load(Unknown Source)
at com.almworks.sqlite4java.Internal.tryLoadFromPath(Internal.java:340)
at com.almworks.sqlite4java.Internal.loadLibraryX(Internal.java:117)
at com.almworks.sqlite4java.SQLite.loadLibrary(SQLite.java:95)
... 9 more
In the terminal that I'm running the cluster of Node workers I'm getting the following error output from each worker (8) and then a DDB error:
Failed to create table in DB.
{ Error: connect ECONNREFUSED 127.0.0.1:8000
at Object.exports._errnoException (util.js:1022:11)
at exports._exceptionWithHostPort (util.js:1045:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:14)
message: 'connect ECONNREFUSED 127.0.0.1:8000',
code: 'NetworkingError',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 8000,
region: 'us-west-2',
hostname: 'localhost',
retryable: true,
time: 2019-01-12T20:31:00.742Z }
DDB Error: NetworkingError: connect ECONNREFUSED 127.0.0.1:8000
I promise I'm finishing this up. Here's my code for creating the DDB table (I pass const ddb = new AWS.DynamoDB() as the parameter from app.js):
const AWS = require('aws-sdk');
function createDDBTable(ddb, tableName) {
// console.log('ddb:\n',ddb);
const tableParams = {
AttributeDefinitions: [
{
AttributeName: 'email',
AttributeType: 'S'
},
{
AttributeName: 'id',
AttributeType: 'S'
}
],
KeySchema: [
{
AttributeName: 'email',
KeyType: 'HASH'
},
{
AttributeName: 'id',
KeyType: 'RANGE'
}
],
ProvisionedThroughput: {
ReadCapacityUnits: 8,
WriteCapacityUnits: 8
},
TableName: tableName,
StreamSpecification: {
StreamEnabled: false
}
};
ddb.createTable(tableParams, (err, data) => {
if(err) console.error('Failed to create table in DB.\n', err);
else console.log('Success creating table!', data);
})
}
module.exports = createDDBTable;
I'm at a loss for where I'm going wrong. All of my validation and endpoints work, however, when it comes time to create a table my code keeps me stumbling through errors. I also have a feeling I may need to adjust my options.config file a bit, but I'm not sure how to format that. Thanks in advance for any help! I tried to be thorough about my issue, but let me know if I can expand on anything else.

instead of http://localhost:port use your computer IP. it will work.
ex: http://xxx.yy.zz.aaa:port <--your computer IP

Related

Connecting to an Azure Redis Cluster using node.js ioredis not working

I've been trying to connect to a Redis three node cluster in Azure using ioredis.
When I connect using the Redis.Cluster constructor:
new Redis.Cluster(['host.redis.cache.windows.net', 6380], {
scaleReads: 'all',
slotsRefreshTimeout: 2000,
redisOptions: {
password: 'some-secret',
tls: true as any
},
});
The error I get is:
2020-06-04T13:05:41.787Z ioredis:cluster getting slot cache from 127.0.0.1:6380
2020-06-04T13:05:41.788Z ioredis:redis status[127.0.0.1:6380 (ioredisClusterRefresher)]: [empty] -> wait
2020-06-04T13:05:41.788Z ioredis:redis status[127.0.0.1:6380 (ioredisClusterRefresher)]: wait -> connecting
2020-06-04T13:05:41.788Z ioredis:redis queue command[127.0.0.1:6380 (ioredisClusterRefresher)]: 0 -> cluster([ 'slots' ])
2020-06-04T13:05:41.790Z ioredis:connection error: Error: connect ECONNREFUSED 127.0.0.1:6380
2020-06-04T13:05:41.791Z ioredis:redis status[127.0.0.1:6380 (ioredisClusterRefresher)]: connecting -> close
2020-06-04T13:05:41.791Z ioredis:connection skip reconnecting because `retryStrategy` is not a function
2020-06-04T13:05:41.791Z ioredis:redis status[127.0.0.1:6380 (ioredisClusterRefresher)]: close -> end
2020-06-04T13:05:41.792Z [auth-middleware] Redis error { ClusterAllFailedError: Failed to refresh slots cache.
at tryNode (/app/node_modules/ioredis/built/cluster/index.js:359:31)
at /app/node_modules/ioredis/built/cluster/index.js:376:21
at duplicatedConnection.cluster.utils_2.timeout (/app/node_modules/ioredis/built/cluster/index.js:624:24)
at run (/app/node_modules/ioredis/built/utils/index.js:156:22)
at tryCatcher (/app/node_modules/standard-as-callback/built/utils.js:11:23)
at promise.then (/app/node_modules/standard-as-callback/built/index.js:30:51)
at process._tickCallback (internal/process/next_tick.js:68:7)
lastNodeError:
Error: Connection is closed.
at close (/app/node_modules/ioredis/built/redis/event_handler.js:179:25)
at TLSSocket.<anonymous> (/app/node_modules/ioredis/built/redis/event_handler.js:150:20)
at Object.onceWrapper (events.js:277:13)
at TLSSocket.emit (events.js:194:15)
at _handle.close (net.js:600:12)
at TCP.done (_tls_wrap.js:388:7) }
When I connect using a non-cluster Redis connection:
new Redis(6380, 'host.redis.cache.windows.net', { password: 'some-secret' });
The error I get is:
020-06-04T15:04:08.609Z ioredis:redis status[10.211.x.x:6380]: connecting -> connect
2020-06-04T15:04:08.614Z ioredis:redis write command[10.211.x.x:6380]: 0 -> auth([ 'some-secret' ])
2020-06-04T15:04:08.616Z ioredis:redis write command[10.211.x.x:6380]: 0 -> info([])
2020-06-04T15:05:16.114Z ioredis:connection error: Error: read ECONNRESET
2020-06-04T15:05:16.115Z [auth-middleware] Redis error { Error: read ECONNRESET
at TCP.onStreamRead (internal/stream_base_commons.js:111:27) errno: 'ECONNRESET', code: 'ECONNRESET', syscall: 'read' }
As you can see it is using TLS on port 6380. Azure provides me with one host+port combination and two different access-keys (primary/seconday) - which I find weird, which access-key should I use? Also I'm not sure if I should be connecting in Cluster mode, but I'd prefer to to gain the benefits of clustering. When I do it appears it tries to find the slots at 127.0.0.1:6380 which is probably not correct.
In Azure's quickstart they connect using node_redis with:
var redis = require("redis");
// Add your cache name and access key.
var client = redis.createClient(6380, process.env.REDISCACHEHOSTNAME,
{auth_pass: process.env.REDISCACHEKEY, tls: {servername: process.env.REDISCACHEHOSTNAME}});
I was hoping someone here would have come across the same issue and solved it.
Thanks!
Okay I've managed to connect to Azure Redis Cluster using a non-tls connection:
new Redis.Cluster(['host.redis.cache.windows.net', 3679], {
scaleReads: 'all',
slotsRefreshTimeout: 2000,
redisOptions: {
password: 'some-secret',
},
})
For some reason connecting to 6380 with TLS enabled does not work.

Error! MongoNetworkError: failed to connect to server - after connect to another wifi network

I created an entire, working application with backend in Node.js and Mongodb (Mean stack). Everything is fine, but when I connect to another wifi network there is an error. Please help me.
If I have to send more code from the app, write it.
Error! MongoNetworkError: failed to connect to server [eventsdb-shard-00-00-ydx5k.mongodb.net:27017] on first connect [MongoNetworkError: connection 5 to eventsdb-shard-00-00-ydx5k.mongodb.net:27017 closed
at TLSSocket.<anonymous>
at Object.onceWrapper (events.js:300:26)
at TLSSocket.emit (events.js:210:5)
at net.js:659:12
at TCP.done (_tls_wrap.js:481:7) {
name: 'MongoNetworkError',
[Symbol(mongoErrorContextSymbol)]: {}
}]
...\App\server\node_modules\mongodb\lib\core\connection\connection.js:372:9 :
function closeHandler(conn) {
return function(hadError) {
if (connectionAccounting) deleteConnection(conn.id);
if (conn.logger.isDebug()) {
conn.logger.debug(`connection ${conn.id} with for [${conn.address}] closed`);
}
if (!hadError) {
conn.emit(
'close',
new MongoNetworkError(`connection ${conn.id} to ${conn.address} closed`), // <------ 372
conn
);
}
};
}
I solved my problem. On the Mongodb website, where I have a database, I entered "Network Access" -> "Add IP Address", I added my new ip address and there was no error.

Prisma binding unable to connect to prisma server. request to http://localhost:4466/ failed, reason: connect ECONNREFUSED 127.0.0.1:4466

I am running two separate docker services. One for my GraphQL server and the other one is a prisma service connecting to a local Postgres database. I am able to run prisma deploy and test it out directly in http://localhost:4466. But When I try to query using my app’s GraphQL server in http://localhost:8080, it gives the following response.
{
"data": null,
"errors": [
{
"message": "request to http://localhost:4466/ failed, reason: connect ECONNREFUSED 127.0.0.1:4466",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"feed"
]
}
]
}
This is the stack trace.
graphql-server_1 | [Network error]: FetchError: request to http://localhost:4466/ failed, reason: connect ECONNREFUSED 127.0.0.1:4466
graphql-server_1 | Error: request to http://localhost:4466/ failed, reason: connect ECONNREFUSED 127.0.0.1:4466
graphql-server_1 | at new CombinedError (/usr/src/app/node_modules/graphql-binding/node_modules/graphql-tools/dist/stitching/errors.js:83:28)
graphql-server_1 | at Object.checkResultAndHandleErrors (/usr/src/app/node_modules/graphql-binding/node_modules/graphql-tools/dist/stitching/errors.js:101:15)
graphql-server_1 | at CheckResultAndHandleErrors.transformResult (/usr/src/app/node_modules/graphql-binding/node_modules/graphql-tools/dist/transforms/CheckResultAndHandleErrors.js:10:25)
graphql-server_1 | at /usr/src/app/node_modules/graphql-binding/node_modules/graphql-tools/dist/transforms/transforms.js:19:54
graphql-server_1 | at Array.reduce (<anonymous>)
graphql-server_1 | at applyResultTransforms (/usr/src/app/node_modules/graphql-binding/node_modules/graphql-tools/dist/transforms/transforms.js:18:23)
graphql-server_1 | at /usr/src/app/node_modules/graphql-binding/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:82:50
graphql-server_1 | at step (/usr/src/app/node_modules/graphql-binding/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:32:23)
graphql-server_1 | at Object.next (/usr/src/app/node_modules/graphql-binding/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:13:53)
graphql-server_1 | at fulfilled (/usr/src/app/node_modules/graphql-binding/node_modules/graphql-tools/dist/stitching/delegateToSchema.js:4:58)
This is how I created the binding
const server = new GraphQLServer({
typeDefs: './src/schema.graphql',
resolvers,
context: req => ({
...req,
db: new Prisma({
typeDefs: './src/generated/prisma.graphql',
endpoint: 'http://localhost:4466',
secret: 'my-secret',
debug: true,
})
})
});
I am not sure as to what is the problem.
Full Code can be found here: https://github.com/dhanushuUzumaki/Journal/tree/feature/setup
Got Help from prisma forum to solve this.
Using localhost within a container points to the container itself and not the host on which the containers are running. So in order to connect to the Prisma instance, you have to use the internal service name which resolves to the respective Prisma container.
...
db: new Prisma({
typeDefs: './src/generated/prisma.graphql',
endpoint: 'http://prisma:4466',
secret: 'my-secret',
debug: true,
})
...
Prisma Forum - ECONNREFUSED - Unable to connect to prisma service through binding
This happened to me when using Docker Toolbox on windows, the endpoint had to be changed from using localhost to the VirtualBox default ip within prisma.yml:
endpoint: http://192.168.99.100:4466

Hazelcast Nodejs Client Connection Refused

I am trying to run the basic example code provided in the "Using the Client" section of https://github.com/hazelcast/hazelcast-nodejs-client
I am getting a connection refused error. I tried this on both my Mac and my PC machines with the same result. They are running Node v6.9.1. I do not have any special firewall settings. Even tried turning of the Windows firewall completely.
Is there something I am missing?
[DefaultLogger] WARN at ClientConnection: Could not connect to address localhost:5701
{ Error: connect ECONNREFUSED 127.0.0.1:5701
at Object.exports._errnoException (util.js:1026:11)
at exports._exceptionWithHostPort (util.js:1049:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1085:14)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 5701 }
Unhandled rejection Error: Unable to connect to any of the following addresses: localhost:5701
at Immediate.<anonymous> (C:\Users\Jennie Lyn\node_modules\hazelcast-client\lib\invocation\ClusterService.js:95:33)
at runCallback (timers.js:637:20)
at tryOnImmediate (timers.js:610:5)
at processImmediate [as _immediateCallback] (timers.js:582:5)
First i created an empty node project then:
npm install hazelcast-client --save
Then created one js file with:
var HazelcastClient = require('hazelcast-client').Client;
var person = {
firstName: "Joe",
lastName: "Doe",
age: 42
};
var map;
HazelcastClient.newHazelcastClient().then(function (hazelcastClient) {
map = hazelcastClient.getMap("personMap");
map.put(1, person).then(function (val) {
// prints previous value for key `1`
console.log(val);
});
map.get(1).then(function (value) {
console.log(value);
})
});
That's all the documentation says to do. Is there something else that needs to be done to start a single client cluster on the localhost using hazelcast-client for nodejs?
Before you start
download latest Hazelcast distribution from https://hazelcast.org/download/
unzip to any folder
start Hazelcast member using startup script /bin/start.sh
you can use samples now
Let me know if it works
Cheers,
Vik

Regarding the error occurred in my test case in nodeload.js script

I have designed an app using elastic search. And when Iam trying to write the test case using node load.js. I have got a problem that when I increase the number users I was getting the warning that "WARN: Error during HTTP request: Error: ECONNREFUSED, Could not contact DNS servers" and Iam unable rectify the problem so please help me in solving this error.
nl.run({
name: "test",
host: 'localhost',
port: 9200,
//path: '/my_river/page/_search?q=sweden',
numUsers: 2000, //Increased my num of user**
timeLimit: 180,
targetRps: 500,
stats: [
'result-codes',
{ name: 'latency', percentiles: [0.9, 0.99] },
'concurrency',
'rps',
'uniques',
{ name: 'http-errors', successCodes: [200,404], log: 'http-errors.log' }
],

Resources