Lambda response callback and leave function running in background

Hi, I’m working on a function need a longer execution time (45s)
I’m expecting to get the “hello world 1” response immediately with the API call, and afterward with the “hello world 2” write into the log

var test_api = (event, context, callback) => {
	callback(null, {
		statusCode: 200,
		body: JSON.stringify({ message: "hello world 1" })
	setTimeout(function() {
		console.log("hello world 2");
	}, 45000);

However it didn’t work, I got the 504 timeout error

  "message": "Endpoint request timed out"

Anyone can help? Thanks!!

Normally I’d trigger a second Lambda via SNS to handle the background tasks.

1 Like

thanks, you’re so helpful!