Search code examples
node.jsaws-lambdascheduled-tasksstate-machineaws-step-functions

Execute a lambda at a defined time which is based on user input


I have an online classroom where I need to execute a recorder lambda function at the start time of the class. The time of the execution depends on the time at which user creates a class. How can I run the function at that time? I found no option for this neither in aws lambda or serverless framework. Is there any other service in aws that could help me out?


Solution

  • I used aws step function's wait to execute my lambda at the start of the classroom.

    stepFunctions:
      stateMachines:
        stepFunction:
          events:
            - http:
                path: classroom/create
                method: POST
          name: classroom-state-machine
          definition:
            StartAt: RecordingWait
            States:
              RecordingWait:
                Type: Wait
                TimestampPath: "$.start"
                Next: StartRecording
              StartRecording:
                Type: Task
                Resource: arn:aws:lambda:ap-southeast-1:13######:function:consult-api-dev-StartRecorder
                End: True
    

    So when I create a classroom, I start the execution of the state machine passing the class start time as an input to the state machine. The state machine will wait till the start time passed in and then go to the next state which is to execute the recording lambda function.