I'm a beginner and I have configured a lambda function with a timeout of 10 minutes and I want to run a certain function inside my lambda function with 30 second time interval. For this I used a 'setInterval()' function and my code look like this, and when I test it Function 1 executes but the function 2 which has to execute every 30 seconds doesn't work. How to fix this?
import { default as fetch, Request } from 'node-fetch';
const GRAPHQL_ENDPOINT = process.env....;
const GRAPHQL_API_KEY = process.env....;
/**
* @type {import('@types/aws-lambda').APIGatewayProxyHandler}
*/
export const handler = async (event) => {
console.log(`EVENT: ${JSON.stringify(event)}`);
let statusCode = 200;
let body;
let response;
async function Func2(){
try {
// function 2 this is called in every 30 seconds, and this is a async function calling a graphql endpoint
};
}catch(error){
statusCode = 400;
body = {
errors: [
{
status: response.status,
message: error.message,
stack: error.stack
}
]
};
}
}
try {
// Function 1, this is an async function calling a graphql endpoint
setInterval(() => Func2(), 30000);
} catch (error) {
statusCode = 400;
body = {
errors: [
{
status: response.status,
message: error.message,
stack: error.stack
}
]
};
return {
statusCode,
body: JSON.stringify(body)
};
}
return {
statusCode,
body: JSON.stringify(body)
};
};