1 00:00:00,360 --> 00:00:01,193 ‫So let's talk 2 00:00:01,193 --> 00:00:05,430 ‫about a step function feature called wait for task token. 3 00:00:05,430 --> 00:00:07,380 ‫So the idea is that you have your step functions 4 00:00:07,380 --> 00:00:09,750 ‫and you have your execution workflow 5 00:00:09,750 --> 00:00:13,050 ‫but then you want to wait for a task token to be returned 6 00:00:13,050 --> 00:00:15,900 ‫because you're waiting for something external. 7 00:00:15,900 --> 00:00:18,840 ‫So you may be waiting for another AWS service 8 00:00:18,840 --> 00:00:21,060 ‫to do its thing or human approval 9 00:00:21,060 --> 00:00:24,270 ‫or a third-party integration or to call legacy systems. 10 00:00:24,270 --> 00:00:26,310 ‫And so to do so, you're going to, 11 00:00:26,310 --> 00:00:28,650 ‫in your task in step functions, 12 00:00:28,650 --> 00:00:33,090 ‫append the .waitForTaskToken to the resource field. 13 00:00:33,090 --> 00:00:35,220 ‫And this is going to tell step functions to wait 14 00:00:35,220 --> 00:00:37,560 ‫for a specific task token to be returned 15 00:00:37,560 --> 00:00:39,840 ‫before the execution can move on. 16 00:00:39,840 --> 00:00:40,680 ‫So for example, 17 00:00:40,680 --> 00:00:45,035 ‫here we have a resource named sqs:sendMessage 18 00:00:45,035 --> 00:00:47,850 ‫and then we waitForTaskToken. 19 00:00:47,850 --> 00:00:51,630 ‫I will show you in the very next slide how that works. 20 00:00:51,630 --> 00:00:53,220 ‫So the task is going to be paused 21 00:00:53,220 --> 00:00:55,950 ‫until it's going to receive a task token back 22 00:00:55,950 --> 00:00:59,700 ‫with either a SendTaskSuccess if everything works 23 00:00:59,700 --> 00:01:02,940 ‫or a SendTaskFailure API call. 24 00:01:02,940 --> 00:01:04,710 ‫So let's take an example of a workflow. 25 00:01:04,710 --> 00:01:07,620 ‫We start, we're going to check the client credits 26 00:01:07,620 --> 00:01:10,020 ‫and this actually relies on an external service. 27 00:01:10,020 --> 00:01:11,040 ‫So what do we do? 28 00:01:11,040 --> 00:01:14,340 ‫We are going to call SQS with a task token. 29 00:01:14,340 --> 00:01:18,900 ‫So we'll use the waitForTaskToken in the resource 30 00:01:18,900 --> 00:01:21,150 ‫and then we pass in the input, 31 00:01:21,150 --> 00:01:23,730 ‫of course, to the SQS queue in the message. 32 00:01:23,730 --> 00:01:26,160 ‫But also, we're going to pass the task token 33 00:01:26,160 --> 00:01:29,430 ‫so that the receiving application knows 34 00:01:29,430 --> 00:01:32,040 ‫how to call back then step functions. 35 00:01:32,040 --> 00:01:34,770 ‫So then your SQS queues may be pulled 36 00:01:34,770 --> 00:01:36,840 ‫by whatever application you may have. 37 00:01:36,840 --> 00:01:38,970 ‫It could be Lambda functions, it could be ECS, 38 00:01:38,970 --> 00:01:41,850 ‫it could be EC2, it could be a third-party server. 39 00:01:41,850 --> 00:01:43,350 ‫It could be whatever you want, right? 40 00:01:43,350 --> 00:01:45,480 ‫But you're going to process the message. 41 00:01:45,480 --> 00:01:46,313 ‫And then, of course, 42 00:01:46,313 --> 00:01:48,330 ‫you're going to get the message input body 43 00:01:48,330 --> 00:01:50,310 ‫but also, you're going to get the task token. 44 00:01:50,310 --> 00:01:53,250 ‫And then if it's successful or a failure, 45 00:01:53,250 --> 00:01:57,210 ‫you're going to use a SendTaskSuccess API call 46 00:01:57,210 --> 00:02:01,440 ‫in which you're going to pass the outputs of the processing 47 00:02:01,440 --> 00:02:05,040 ‫but also the task token that was passed initially 48 00:02:05,040 --> 00:02:06,690 ‫to your SQS queue. 49 00:02:06,690 --> 00:02:10,350 ‫And then once the step function workflow receives 50 00:02:10,350 --> 00:02:13,320 ‫that API call with the correct task token 51 00:02:13,320 --> 00:02:16,770 ‫and the correct output, then you can go on and, for example, 52 00:02:16,770 --> 00:02:18,780 ‫do the rest of your workflow. 53 00:02:18,780 --> 00:02:21,810 ‫But the benefit of this is that we were able to rely 54 00:02:21,810 --> 00:02:25,620 ‫upon an external system to perform some processing 55 00:02:25,620 --> 00:02:28,800 ‫before we got back into our step functions workflow. 56 00:02:28,800 --> 00:02:30,259 ‫And this is how you can integrate 57 00:02:30,259 --> 00:02:33,510 ‫with any kind of external mechanism. 58 00:02:33,510 --> 00:02:34,470 ‫So that's it for this lecture 59 00:02:34,470 --> 00:02:37,713 ‫I hope you liked it and I will see you in the next lecture.