Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
skytreader opened this issue Jul 22, 2019 · 2 comments
Open

Comments

@skytreader
Copy link

skytreader commented Jul 22, 2019

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
Copy link

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

@skytreader
Copy link
Author

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

@skytreader skytreader changed the title EHOSTUNREACH when providing credentials via JSON file EHOSTUNREACH when providing credentials via JSON file or creating data Jul 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants