Do I need to return AWS Lambda to use node.js and not perform any further processing after callback()?

Asked 2 years ago, Updated 2 years ago, 91 views

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?

aws-lambda

2022-09-30 19:14

1 Answers

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.


2022-09-30 19:14

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.