Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 786
warmjaijai Avatar asked Apr 30 '18 08:04

warmjaijai


People also ask

How do I connect to AWS DynamoDB locally?

To access DynamoDB running locally, use the --endpoint-url parameter. The following is an example of using the AWS CLI to list the tables in DynamoDB on your computer. The AWS CLI can't use the downloadable version of DynamoDB as a default endpoint. Therefore, you must specify --endpoint-url with each AWS CLI command.

How do I get DynamoDB credentials?

Sign in to the AWS Management Console and open the IAM console at https://console.aws.amazon.com/iam/ . In the navigation pane, choose Users. Choose the name of the user whose access keys you want to create, and then choose the Security credentials tab. In the Access keys section, choose Create access key.

Where are AWS credentials stored?

The credentials file is located at ~/.aws/credentials on Linux or macOS, or at C:\Users\ USERNAME \.aws\credentials on Windows. This file can contain the credential details for the default profile and any named profiles.


1 Answers

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.

like image 127
roxxypoxxy Avatar answered Nov 15 '22 11:11

roxxypoxxy