I'm trying to use the ogr2gr module in a lambda function but I'm having some issues with it, so I wanted to see if anyone tried to use the module in a lambda function? The way I am using the ogr2ogr module is by doing .promise()
. However when I try to run my lambda function, I don't see anything in the logs. It seems like it just never hits the promise? Here is how my code looks like with the promise:
let data = await ogr2ogr(path)
.destination(database)
.options(['-f "PostgreSQL"', '-nlt PROMOTE_TO_MULTI', 'nln <schemaName>."' + tableName + '"', '-overwrite']).promise();
console.log(data);
I'm doing it exactly the way the documentation says but it still doesn't work. Something I should point out is that I tried to do
let ogr = ogr2ogr(path)
.destination(database)
.options(['-f "PostgreSQL"', '-nlt PROMOTE_TO_MULTI', 'nln <schemaName>."' + tableName + '"', '-overwrite']);
console.log(ogr);
And I actually see the EventEmitter in the logs:
EventEmitter {
_inPath: '<path_of_file>',
_onStderr: [Function (anonymous)],
_driver: {},
_args: [],
_timeout: 15000,
_format: 'GeoJSON',
_skipfailures: false,
_testClean: [Function (anonymous)],
_destination: <database information>,
_options: [
'-f "PostgreSQL"',
'-nlt PROMOTE_TO_MULTI',
'nln useradministration.tableName',
'-overwrite'
]
}
But if I try to do a callback like the documentation says, using the .exec()
function, I don't see anything outputted:
let ogr = ogr2ogr(path)
.destination(database)
.options(['-f "PostgreSQL"', '-nlt PROMOTE_TO_MULTI', 'nln <schemaName>."' + tableName + '"', '-overwrite']);
console.log(ogr);
ogr.exec(function (er, data) {
if (er) {
console.error(er);
}
console.log(data);
});
I'm honestly stumped at this point and not sure what to do. Any help is greatly appreciated, like if anyone had a similar issue or maybe an explanation as to why the promise nor callback works in the lambda function.
It turns out that my lambda timeout was at 3 seconds and the promise was taking longer than 3 seconds, resulting in the lambda timing out and me seeing no results in the logs.