warmjaijai
warmjaijai

Reputation: 1011

AWS DynamoDB Missing credentials in config in local dev environment

My colleague successfully perform the following code showing the table without setting the credentials in local environment, but when i conduct it it shows such error on my local machine. Please help.

Please find my codes below:

Controller:

    AWS.config.update({
        region: 'localhost',
        endpoint: new AWS.Endpoint('http://localhost:8008'),
    })
    var params = {
        TableName: 'history',
        KeySchema: [{
            AttributeName: 'b_id',
            KeyType: 'HASH'
        },{
            AttributeName: 'e_id',
            KeyType: 'RANGE'
        }],
        AttributeDefinitions: [{
            AttributeName: 'b_id',
            AttributeType: 'S',
        },{
            AttributeName: 'e_id',
            AttributeType: 'N',
        }],
        ProvisionedThroughput: { // required provisioned throughput for the table
            ReadCapacityUnits: 1, 
            WriteCapacityUnits: 1, 
        },
    }
    response.implicitEnd = false
    AWS.query('history',params, function(err, data){
        if(err) console.log(err)
        else  response.json(data)
    })

Error Message:

{ Error: connect EHOSTUNREACH 169.254.169.254:80 - Local () at Object._errnoException (util.js:1022:11) at _exceptionWithHostPort (util.js:1044:20) at internalConnect (net.js:971:16) at net.js:1065:9 at _combinedTickCallback (internal/process/next_tick.js:131:7) at process._tickDomainCallback (internal/process/next_tick.js:218:9) message: 'Missing credentials in config', code: 'CredentialsError', errno: 'EHOSTUNREACH', syscall: 'connect', address: '169.254.169.254', port: 80, time: 2018-04-30T04:34:53.218Z, originalError: { message: 'Could not load credentials from any providers', code: 'CredentialsError', errno: 'EHOSTUNREACH', syscall: 'connect', address: '169.254.169.254', port: 80, time: 2018-04-30T04:34:53.218Z, originalError: { code: 'EHOSTUNREACH', errno: 'EHOSTUNREACH', syscall: 'connect', address: '169.254.169.254', port: 80, message: 'connect EHOSTUNREACH 169.254.169.254:80 - Local ()' } } }

> which python 
/usr/bin/python

> pip install --upgrade pip
Requirement already up-to-date: pip in /Library/Python/2.7/site-packages (10.0.1)
metplotlib 1.3.1 requires nose, which is not installed.
matplotlib 1.3.1 requires tornado, which is not installed.

> pip --version
pip 10.0.1 from /Library/Python/2.7/site-packages/pip (python 2.7)

> echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

> python --version
Python 2.7.10

Upvotes: 8

Views: 11190

Answers (3)

roxxypoxxy
roxxypoxxy

Reputation: 3121

This is what's working for me

AWS.config.update({
  region: 'us-east-1',
  accessKeyId: 'xxxx',
  secretAccessKey: 'xxxx',
  endpoint: 'http://localhost:8000'
});

const dynamodb = new AWS.DynamoDB()
const dynamoDbClient = new AWS.DynamoDB.DocumentClient();

The accessKeyId and secretAccessKey does not need to be real values.

Upvotes: 19

warmjaijai
warmjaijai

Reputation: 1011

Though Stu informs about the configuration, just to hope people encounter the same as what I did trying to put it to work on localhost. after typing awscli aws configure, as it asked you for the access ID and secret access ID, you have to at least type in something to make it work (cannot leave it blank) so that it will create config files at ~/.aws directory, where in my case I simply just typed in a for both entry, then region:localhost and output:json though i think region is really just up to you. Please help to refine my answer, at least this works out for me allowing me to continue using DynamoDB on local machine

Upvotes: 2

F_SO_K
F_SO_K

Reputation: 14849

Once configured AWS credentials are stored in a local configuration file. For windows the file can be found at

%UserProfile%\.aws\credentials

For linux the file can be found at

~/.aws/credentials

You need to have this file available. Install AWS CLI. Then to configure this file open a command line on your local machine and enter

aws configure

Details on the CLI setup are here. Details of the credentials file are here.

Upvotes: 4

Related Questions