baseprime / dynamodb

DynamoDB data mapper for Node.js
Other
297 stars 88 forks source link

EHOSTUNREACH when providing credentials via JSON file or creating data #62

Open skytreader opened 5 years ago

skytreader commented 5 years ago

Package version: 1.2.0

node version: 10.16.0

Take this code:

var dynamo = require("dynamodb");
dynamo.AWS.config.loadFromPath("/home/me/.aws/credentials.json");

Running this with node index.js results to

Error: connect EHOSTUNREACH 169.254.169.254:80
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1106:14)

But hardcoding the credentials like as follows:

var dynamo = require("dynamodb");
dynamo.AWS.config.update({ "aws_access_key_id": "REDACTED", "aws_secret_access_key": "redacted", "region": "eu-west-1" })

has no problems.

What gave me the hint to try spelling out the JSON in code is aws/aws-sdk-js#2534.

Why does this happen and are there any workarounds to specifying JSON files for credentials? Is this a fault with this dynamodb package or should I air my woes in aws/aws-sdk-js? I could work with the hardcoded credentials for now but later on reading from JSON files would be really preferred.

UPDATE:

Upgrading aws-sdk to 2.497.0 or downgrading to 2.186.0 helps with the config loading part. But then the same error crops up when I try to insert anything to DynamoDB:

const dynamo = require("dynamodb");
const Joi = require("@hapi/joi");
// This bit is ok
dynamo.AWS.config.loadFromPath("/home/me/.aws/credentials.json");

var TestTable = dynamo.define("test-table", {
  hashKey: "name",
  schema: {
    "name": Joi.string(),
    "age": Joi.number().integer()
  }
});

console.log("Creating tables...");
dynamo.createTables((err) => {
  if (err) {
    console.log("Error creating tables: ", err);
  } else {
    console.log("Tables have been created.");
  }
});
console.log("done creating tables.");

// aaannnnddd POOF!
TestTable.create({"name": "Chad", "age": 26});

The exact error being

me@PC-6FS6P02:lmt-pubsub-cache$ node test.js 
Creating tables...
done creating tables.
/home/me/project/node_modules/aws-sdk/lib/config.js:412
      if (err) throw err;
               ^

Error: connect EHOSTUNREACH 169.254.169.254:80
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1106:14)
ursravis commented 5 years ago

Updating aws-sdk to latest version @2.497.0 solved this problem for me.

skytreader commented 5 years ago

I don't have aws-sdk directly in my dependencies though:

  "dependencies": {
    "@hapi/joi": "^15.1.0",
    "aws-sns-publish": "^3.3.0",
    "dynamodb": "^1.2.0",
    "express": "^4.17.1"
  }

But I see that version 2.496.0 is installed, as required by this library. However this library specifies "^2.186.x" for the version of aws-sdk it needs. Perhaps this bug is reason enough to change this? Either,

a. strictly peg it to a 2.186.something release (maybe ~2.186.0 would be acceptable) b. specify ~2.497.0, or a strict 2.497.0