当前位置 : 主页 > 网页制作 > Nodejs >

node.js – Amazon Kinesis NodeJS – putRecord操作过期

来源:互联网 收集:自由互联 发布时间:2021-06-16
我使用NodeJS和 Express作为代理来处理HTTP GET请求,对数据进行一些小的调整,并将数据提交给Amazone Kinesis.以下是我的代码摘录: var express = require('express');var app = express();app.get('/proxy-test',
我使用NodeJS和 Express作为代理来处理HTTP GET请求,对数据进行一些小的调整,并将数据提交给Amazone Kinesis.以下是我的代码摘录:

var express = require('express');
var app = express();


app.get('/proxy-test', function(req, res){
    var data = req.query;

    // perform some light data processing

    // send results to kinesis
    kinesis.putRecord({
        StreamName : MY_STREAM_NAME,
        Data : data,
        PartitionKey : MY_PARTITION_KEY
    }, function(err, data) {
        if (err) {
            console.log(err, err.stack); // an error occurred
        } else {
            console.log(data);
        }
    });

    res.send(200);
});

在为200个并发用户运行JMeter测试(循环100次)后,5分钟后,我收到此错误:

{ [InvalidSignatureException: Signature expired: 20140409T152855Z is now earlier than 20140409T153211Z (20140409T153711Z – 5 min.)]
message: ‘Signature expired: 20140409T152855Z is now earlier than 20140409T153211Z (20140409T153711Z – 5 min.)’,
code: ‘InvalidSignatureException’,
time: Wed Apr 09 2014 17:37:11 GMT+0200 (CEST),
statusCode: 400,
retryable: false,
_willRetry: false } ‘InvalidSignatureException: Signature expired: 20140409T152855Z is now earlier than 20140409T153211Z (20140409T153711Z – 5 min.)\n at Request.extractError (/Users/me/proxy/node_modules/aws-sdk/lib/service_interface/json.js:43:33)\n at Request.callListeners (/Users/me/proxy/node_modules/aws-sdk/lib/sequential_executor.js:114:20)\n at Request.emit (/Users/me/proxy/node_modules/aws-sdk/lib/sequential_executor.js:81:10)\n at Request.emit (/Users/me/proxy/node_modules/aws-sdk/lib/request.js:578:14)\n at Request.transition (/Users/me/proxy/node_modules/aws-sdk/lib/request.js:12:12)\n at AcceptorStateMachine.runTo (/Users/me/proxy/node_modules/aws-sdk/lib/state_machine.js:14:12)\n at /Users/me/proxy/node_modules/aws-sdk/lib/state_machine.js:26:10\n at Request. (/Users/me/proxy/node_modules/aws-sdk/lib/request.js:28:9)\n at Request. (/Users/me/proxy/node_modules/aws-sdk/lib/request.js:580:12)\n at Request.callListeners (/Users/me/proxy/node_modules/aws-sdk/lib/sequential_executor.js:90:20)’

我能做些什么(配置或代码更改)以确保发送和保存所有Kinesis记录?

你可能在Kinesis生产者实例(你正在运行NodeJS的实例)上遇到时钟漂移.在查询各种服务(不仅仅是Kinesis)的AWS API时,我们经常会看到这种情况.

安装和配置ntp以使用NTP池中的AWS节点非常常见:

sudo apt-get -qy install ntp
sudo sed -i -r 's/^(server\s[0-3]\.)ubuntu([a-z\.]+)/\1amazon\2 iburst/' /etc/ntp.conf
sudo sed -i -r 's/^(server\sntp\.ubuntu\.com)/#\1\nserver time.nist.gov/' /etc/ntp.conf
sudo service ntp restart

如果您有兴趣,可以在此处链接到更多文档:

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/set-time.html

网友评论