I'm wondering if I should write a return right after callback() in Lambda.
We have verified that the following scripts run console.log()
or later:
'use strict';
module.exports.helloWorld=(event, context, callback)=>{
const response = {
statusCode: 200,
headers:{
'Access-Control-Allow-Origin': '*', // Required for CORS support to work
},
body: JSON.stringify({
message: 'message🐷',
input:event,
}),
};
callback (null, response);
console.log('🐸', 'log2 after callback!')
};
Does that mean that if I use callback
like an early return using an if statement, unexpected behavior will occur?(If you think about it normally, it will be like that.)
To prevent this, I understand that return
should be done immediately after callback
, but I am not confident because I have never personally seen such a code.Should I?
Callback is a function that only sets the return value, so the process does not end.
Therefore, if you don't want to take any further action, you should return it, and I don't think you need to write the code after callback in the first place.
© 2024 OneMinuteCode. All rights reserved.