0

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?

Yasith Prabuddhaka
  • 859
  • 1
  • 11
  • 17

1 Answers1

1

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.

Diego Jancic
  • 7,280
  • 7
  • 52
  • 80
  • Thanks for your opinion @DiegoJancic. I have not used Step Functions service earlier but I will have a look. The second option does not work for me since I cannot be manually doing anything. – Yasith Prabuddhaka Dec 18 '18 at 04:07
  • 1
    The second option can be done via an API call. It's a pretty bad solution probably as that service is not intended to be creating and removing rules, but still possible probably. Step Function is the correct to go IMO. – Diego Jancic Dec 18 '18 at 04:11
  • 1
    Thanks @DiegoJancic. I'm going through Step Function now. I will mark this as resolved if I managed to solve it with Step Function. – Yasith Prabuddhaka Dec 18 '18 at 04:17
  • I resolved this using aws step functions. I will post my blog regarding it shortly. Thanks – Yasith Prabuddhaka Apr 19 '19 at 06:20