Closed joshk132 closed 4 years ago
@joshk132 thanks! Based on this example: https://github.com/influxdata/influxdb-client-js/blob/master/examples/write.js#L30
It looks like you can call writeApi.flush()
after each SQS message if you'd like to write after each point. Also, i'm not a lambda expert, but if you are closing the connection after each function call, I think you will need to open it inside the function call as well. If you change it to use flush
, you might be ok.
What is the solution for this? I'm encountering the same problem...
writeApi.flush() doesn't fix it.
@joshk132 @ZaneL
Try this:
module.exports.perf = async (event, context, callback) => {
context.callbackWaitsForEmptyEventLoop = false;
const writeApi = new InfluxDB({url: InfluxURL, token}).getWriteApi(org, bucket, 'ms')
let input = JSON.parse(event.Records[0].body);
console.log(input)
const point1 = new Point('elapsedTime')
.tag(input.foo, 'foo')
.floatField('value', input.bar)
try {
writeApi.writePoint(point1)
const result = await writeApi.close()
console.log(result)
} catch(e){
console.error(e)
console.log('\nFinished ERROR')
})
return true
};
Please see also https://community.influxdata.com/t/problem-writing-to-influxdb-cloud-from-aws-lambda/15705/3 , it might be relevant as well.
Thank you!
That was the problem -- looks like I just needed to await on writeApi.close()
Steps to reproduce:
Expected behavior: I expect it to write every data point to the DB for each SQS message - takes one message with one data point per lambda execution.
Actual behavior: It fills the buffer - which IDK how to clear - and prevents any data from being written to the DB
Environment info: Cloud offering free tier on AWS us-west-2
Logs:
ERROR: Retry buffer closed with 1 items that were not written to InfluxDB!
Notes: I did manage to write one data point a few days ago and since then it has been not letting me write anything saying the buffer is full