I have a lambda function (say A) which needs to invoke another lambda function (say B). But that other function (B) should not run at the time of invoke but should run at the time defined by A.
Given below is how I'm trying to invoke function B inside function A.
function startRecording(startTime, roomName) {
const payload = {
roomName
}
const param = {
FunctionName: 'consult-classroom-api-dev-StartRecording',
InvocationType: "RequestResponse",
Payload: JSON.stringify(payload)
}
return new Promise((resolve, reject) => {
lambda.invoke(param,(err, data) => {
if (err) {
reject(err);
} else {
let payload = JSON.parse(data.Payload);
let payloadBody = JSON.parse(payload.body);
resolve(payloadBody);
}
}
);
});
}
So I have the start time with me. Need a way to invoke function B at that time. Can anyone suggest a way or work around if this is not possible in aws?
That's not possible using only Lambda. You cannot execute a Lambda at a certain time using only the Lambda service and without executing any functions.
I only can think of 2 options:
1) Using the Step Functions service. That service lets you coordinate the Lambda execution and has a "Wait" step you can use to introduce a delay between one function execution and the other one.
2) You could use CloudWatch > Event Rules to schedule a function execution and after it executes, remove the rule. It would be more work as it's not intended for that use case, but it's doable.