Docker Dynamodb错误:带有dynamodb的Nodejs应用程序在docker中不起作用,但没有它

时间:2017-06-29 08:06:32

标签: node.js amazon-dynamodb

我创建了一个简单的nodejs应用程序,在dynamodb中只有一个表。我使用Vogels作为datawrapper。 如果我不停靠它,它的效果非常好。

我尝试运行docker,就像我在开发模式下运行应用程序一样。那也行不通。

以下是我用来创建表的代码:

module.exports = function () {
    const vogels = require('vogels');
    // const AWS= require('aws-sdk');
    const Lr = require("../api/models/LRModel");
    if (process.env.NODE_ENV === "test") {
        AWS.config.update({ accessKeyId: "myKeyId", secretAccessKey: "secretKey", region: "us-west-2" });
        vogels.dynamoDriver(new AWS.DynamoDB({ endpoint: 'http://localhost:8000' }));
    } else {
        console.log("AWS access key=", process.env.AWS_ACCESS_KEY, "AWS Secret key=", process.env.AWS_SECRET_KEY, "AWS Region =", process.env.AWS_REGION);
        vogels.AWS.config.update({accessKeyId: process.env.AWS_ACCESS_KEY, secretAccessKey: process.env.AWS_SECRET_KEY, region: process.env.AWS_REGION, sslEnabled: false });

    }

    vogels.createTables({
        'lrs': {readCapacity: 10, writeCapacity: 10}
    }, function(err) {
        if (err) {
            console.log('Error creating tables: ', err);
        } else {
            console.log('Tables have been created');
        }
    });
}

以下是我在docker中遇到的错误:

server-0   | Error creating tables:  { TimeoutError: Missing credentials in config
server-0   |     at ClientRequest.<anonymous> (/app/node_modules/vogels/node_modules/aws-sdk/lib/http/node.js:61:34)
server-0   |     at ClientRequest.g (events.js:291:16)
server-0   |     at emitNone (events.js:86:13)
server-0   |     at ClientRequest.emit (events.js:185:7)
server-0   |     at Socket.emitTimeout (_http_client.js:626:10)
server-0   |     at Socket.g (events.js:291:16)
server-0   |     at emitNone (events.js:86:13)
server-0   |     at Socket.emit (events.js:185:7)
server-0   |     at Socket._onTimeout (net.js:339:8)
server-0   |     at ontimeout (timers.js:365:14)
server-0   |   message: 'Missing credentials in config',
server-0   |   code: 'CredentialsError',
server-0   |   time: 2017-06-29T05:36:23.724Z,
server-0   |   originalError:
server-0   |    { message: 'Could not load credentials from any providers',
server-0   |      code: 'CredentialsError',
server-0   |      time: 2017-06-29T05:36:23.724Z,
server-0   |      originalError:
server-0   |       { message: 'Missing credentials in config',
server-0   |         code: 'CredentialsError',
server-0   |         time: 2017-06-29T05:36:23.721Z,
server-0   |         originalError: [Object] } } }

当我运行 WITHOUT docker时,我清楚地注意到的一点是,dynamodb终点是 http 终点。以下是从https://github.com/aws/aws-sdk-js/blob/8904e9c730fb2fccf9d201f66266a6e2cbb75348/lib/http/node.js起登录的端点 (第13行)。

server-0   |   Endpoint {
server-0   |   protocol: 'https:',
server-0   |   host: 'dynamodb.us-west-1.amazonaws.com',
server-0   |   port: 443,
server-0   |   hostname: 'dynamodb.us-west-1.amazonaws.com',
server-0   |   pathname: '/',
server-0   |   path: '/',
server-0   |   href: 'https://dynamodb.us-west-1.amazonaws.com/',
server-0   |   constructor: { [Function: Endpoint] __super__: [Function: Object] } }

当我运行 WITH docker时,dynamodb终点是 httpS 终点。以下是从https://github.com/aws/aws-sdk-js/blob/8904e9c730fb2fccf9d201f66266a6e2cbb75348/lib/http/node.js起登录的端点 (第13行)。

server-0   |   Endpoint {
server-0   |   protocol: 'http:',
server-0   |   host: '169.254.169.254',
server-0   |   port: 80,
server-0   |   hostname: '169.254.169.254',
server-0   |   pathname: '/latest/meta-data/iam/security-credentials/',
server-0   |   path: '/latest/meta-data/iam/security-credentials/',
server-0   |   href: 'http://169.254.169.254/latest/meta-data/iam/security-credentials/' }

我在哪里错了?

1 个答案:

答案 0 :(得分:1)

当我在不使用泊坞窗的情况下运行应用时,正在从handlelist = [plt.plot([],color=color)[0] for color in colors] plt.legend(handlelist,colors,loc=0, ncol=4) 中提取凭据。通过/.aws/credentials

,我感受到了这种印象

我在vogels.AWS.config.update({accessKeyId: process.env.AWS_ACCESS_KEY, secretAccessKey: process.env.AWS_SECRET_KEY, region: process.env.AWS_REGION, sslEnabled: false });的config.js中记录了更新功能中的选项,并在朋友输入的帮助下找到了这个选项。

罪魁祸首似乎是表定义应该在更新配置之后。 我带了这一行aws-sdk 在config.update下面,它现在运行良好