InvalidSignatureException发生在尝试使用Kinesis Producer库添加用户记录时。AWS_JAVA_SDK_VERSION=1.10.26
AWS_KINESIS_producter_VERSION=0.10.1
错误:
PutRecords失败:{"__type":"InvalidSignatureException","message":"我们计算的请求签名与您提供的签名不匹配。请检查您的AWS密钥和签名方法。
SCALA KINESIS生产商代码
private val configuration: KinesisProducerConfiguration = new KinesisProducerConfiguration
val credentialsProvider: AWSCredentialsProvider = AwsUtil.getAwsCredentials(config.awsAccessKey, config.awsSecretKey)
configuration.setCredentialsProvider(credentialsProvider)
configuration.setRecordMaxBufferedTime(config.timeLimit)
configuration.setAggregationMaxCount(1)
configuration.setRegion(config.streamRegion)
configuration.setMetricsLevel("none")
private val kinesisProducer = new KinesisProducer(configuration)
kinesisProducer.addUserRecord(streamName, key, eventBytes)`
上面的代码不起作用。但我可以通过aws-cli从终端和KinesisClient在下面指定的代码中向kinesis流添加记录。
private def createKinesisClient = {
val accessKey = config.awsAccessKey
val secretKey = config.awsSecretKey
val credentialsProvider: AWSCredentialsProvider = AwsUtil.getAwsCredentials(accessKey, secretKey)
val client = new AmazonKinesisClient(credentialsProvider)
client.setEndpoint(config.streamEndpoint)
client
}
发生这种情况是因为您的VM/PC/Server时钟可能发生偏移。
如果你正在运行ubuntu,请尝试更新你的系统时间:
sudo ntpdate ntp.ubuntu.com
如果你在Mac上使用docker-machine
,你可以用这个命令解决:
docker-machine ssh default 'sudo ntpclient -s -h pool.ntp.org'