handle 'SIGTERM' signal on AWS Batch Job using NodeJS

121 views Asked by At

I'm trying to capture this 'SIGTERM' signal that AWS sends just before revoking a SPOT instance or when the job timed out.

Using the function below, I can't see the log, it seems that this function doesn't even execute.

process.on('SIGTERM', () => console.log('test SIGNTERM'))

the following error appears in the logs:

npm ERR! path /
npm ERR! command failed
npm ERR! signal SIGTERM
npm ERR! command sh -c -- NODE_ENV=dev npx babel-node --presets @babel/preset-env src/functions/entries.js 
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2023-09-27T17_54_18_152Z-debug-0.log

Anyone already face it?

My code:

process.on('SIGTERM', () => {
  Logger.info('Application received SIGTERM signal');
  process.exit(0);
}

const executeJob = async () => {  
    await sleep(40 * 60 * 1000);
}

executeJob();

I made it just for a test, i put a 5 minutes timeout on Job and insert that sleep to get timeout inside AWS Batch Job. That log inside process.on didnt appears.

0

There are 0 answers