I am trying to execute a shell command to migrate from the AWS lambda. The idea is that whenever we need to run the migration, we will call the lambda via AWS CLI. I am unable to make it run. The command to run migration never gets executed and it's always response with null. Any help would be greatly appreciated.
This is the code I have :
const exec = require("child_process").exec;
const { okResponse, errorResponse } = require('./response');
exports.handler = async (event) => {
exec("node ./node_modules/db-migrate/bin/db-migrate up --config=./database.json", (error, stdout, stderr) => {
if (error) {
console.error(`error: ${error.message}`);
return errorResponse(500, 'Error running migration.');
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return errorResponse(500, 'Error running migration.');
}
console.log(`stdout: ${stdout}`);
return okResponse(200, 'Migration successfully.');
});
}
awaitbefore your command execution lineawait exec("node ./node_modules/db-migrate/bin/db-migrate up