skip to Main Content

We created step function (WAIT State) to execute schedule task based up on user input time.
We are calling this step up function from PHP code so it will create entry in that state machine and step function (WAIT State) will trigger lambda service automatically when it meets countdown timer.

My requirement is to user to have the option to update the time or cancel event from PHP application. at this scenario i have to update existing scheduled step function event/task time to new time or delete the existing scheduled event and create new scheduled event with latest time.

How can i do with this from PHP application?

The below is my PHP code to create event in AWS step function.

$inputData = '{'.'"invocationTime"'. " : " .'"'.'2022-10-28T13:15:16Z.'"'.','.'"userid"'. " : " .'"1233345"'.'}';
$data = array(
    //This is the schedule in UTC time.
    'input' => $inputData,
    'name' => 'Test Charan",          
    //STATIC
    'stateMachineArn' => $awsDataarn //AWS stateMachineArn
);

$inputdataaws = array(
    'http' => array(                
        'method'  => 'POST',                
        'content' => json_encode($data),                
        'header'  => "x-api-key: ".$awsDataapiKey."rn".
        "Content-Type: application/jsonrn"
    )
);

$url = 'https://testcharan.execute-api.us-east-1.amazonaws.com/myapplication/scheduletask'; //AWS endpoint URL
$request  = stream_context_create($inputdataaws); // TO create data in AWS statemachine
$result = file_get_contents($url, false, $request); //read the data
$response = json_decode($result); //decode the result

The above code will create the event in AWS step function.

enter image description here

How i can update or delete or abort events/execution those or on Running status?

2

Answers


  1. you can’t modify a state machine directly on runtime (on my experiece).
    I suggest to

    1. manage the scheduling of the execution by eventbridge (https://docs.aws.amazon.com/step-functions/latest/dg/tutorial-cloudwatch-events-target.html)
    2. create another Lambda that act as "trigger"
    3. manage state machine execution by cli
      How to stop all running Step Functions of a specific state machine?
    Login or Signup to reply.
  2. It is likely that your use-case could benefit from the callback pattern which will cause your state machine execution to wait for an event for the $$.Task.Token to be received. You can set a timeout by providing a HeartbeatSeconds which will cause the task to fail with States.Timeout.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search