1 00:00:00,400 --> 00:00:03,170 ‫Now let's discuss AWS step functions. 2 00:00:03,170 --> 00:00:04,510 ‫So step functions allow you 3 00:00:04,510 --> 00:00:06,970 ‫to model a workflow as state machines 4 00:00:06,970 --> 00:00:10,760 ‫and you have one state machine per workflow. 5 00:00:10,760 --> 00:00:12,020 ‫So this could be used if you want 6 00:00:12,020 --> 00:00:14,770 ‫to have an order fulfillment or data processing, 7 00:00:14,770 --> 00:00:17,310 ‫a web application or any workflow you want. 8 00:00:17,310 --> 00:00:19,460 ‫The idea is that you will define 9 00:00:19,460 --> 00:00:21,880 ‫what happens and what happens next, 10 00:00:21,880 --> 00:00:23,590 ‫and then what happens based on some condition 11 00:00:23,590 --> 00:00:25,950 ‫and so on to define a workflow. 12 00:00:25,950 --> 00:00:27,520 ‫So as you can see on the right hand side, 13 00:00:27,520 --> 00:00:28,880 ‫there's a visual workflow. 14 00:00:28,880 --> 00:00:31,330 ‫We start and we have an example, 15 00:00:31,330 --> 00:00:32,310 ‫is it yes or no? 16 00:00:32,310 --> 00:00:33,890 ‫If it's no, then you go to the end. 17 00:00:33,890 --> 00:00:35,940 ‫If it's yes, then you wait three seconds. 18 00:00:35,940 --> 00:00:37,520 ‫Then you say, "Hello" and "World," 19 00:00:37,520 --> 00:00:39,140 ‫you compile the result into "Hello World" 20 00:00:39,140 --> 00:00:40,370 ‫and you go into end. 21 00:00:40,370 --> 00:00:42,990 ‫So we'll be going through hands-on to make it specific 22 00:00:42,990 --> 00:00:46,250 ‫but the idea is that you define a workflow in JSON 23 00:00:46,250 --> 00:00:47,970 ‫and this JSON allows you to get 24 00:00:47,970 --> 00:00:49,700 ‫a visualization of the workflow 25 00:00:49,700 --> 00:00:51,760 ‫and then it gets executed visually, 26 00:00:51,760 --> 00:00:55,430 ‫and then we can see the history of the execution itself. 27 00:00:55,430 --> 00:00:57,040 ‫So the idea is that every little step 28 00:00:57,040 --> 00:00:58,950 ‫in the workflow is going to be, for example, 29 00:00:58,950 --> 00:01:02,150 ‫a Lambda function or inserting data into DynamoDB 30 00:01:02,150 --> 00:01:03,940 ‫or a specific ECS task, 31 00:01:03,940 --> 00:01:05,440 ‫and the step function is going to be 32 00:01:05,440 --> 00:01:08,680 ‫the thing that orchestrates this workflow for you. 33 00:01:08,680 --> 00:01:12,240 ‫To start a workflow, you can use an SDK API call, 34 00:01:12,240 --> 00:01:15,410 ‫you can use API gateway, you can use CloudWatch Events 35 00:01:15,410 --> 00:01:18,220 ‫or Amazon EventBridge, they're the same thing, 36 00:01:18,220 --> 00:01:19,830 ‫or you can launch, obviously, 37 00:01:19,830 --> 00:01:21,690 ‫a step function manually from the console, 38 00:01:21,690 --> 00:01:23,960 ‫as we will be doing it in the hands-on. 39 00:01:23,960 --> 00:01:26,950 ‫So step functions have a bunch of boxes 40 00:01:26,950 --> 00:01:28,360 ‫as you see on the right hand side 41 00:01:28,360 --> 00:01:30,660 ‫and these boxes are called tasks. 42 00:01:30,660 --> 00:01:33,530 ‫And so the task state is used to do some work 43 00:01:33,530 --> 00:01:34,980 ‫in your state machine. 44 00:01:34,980 --> 00:01:38,490 ‫So the task state could be invoking a Lambda function 45 00:01:38,490 --> 00:01:42,060 ‫or it could be invoking a Batch job 46 00:01:42,060 --> 00:01:45,340 ‫or running an ECS task and wait for it to complete 47 00:01:45,340 --> 00:01:47,360 ‫or to insert an item directly 48 00:01:47,360 --> 00:01:49,700 ‫from step functions into the DynamoDB 49 00:01:49,700 --> 00:01:52,670 ‫or to publish a message into SNS or SQS 50 00:01:52,670 --> 00:01:55,730 ‫or even to launch another step function workflow. 51 00:01:55,730 --> 00:01:58,540 ‫All these things can be defined in a task state, 52 00:01:58,540 --> 00:02:02,080 ‫or a task could also be running one activity 53 00:02:02,080 --> 00:02:05,070 ‫and that activity could be an EC2 machine 54 00:02:05,070 --> 00:02:07,650 ‫or an Amazon ECS task or on-premises server 55 00:02:07,650 --> 00:02:09,380 ‫that is going to be pulling for some work 56 00:02:09,380 --> 00:02:11,220 ‫from step functions to do the work 57 00:02:11,220 --> 00:02:13,930 ‫and then send back the results to the step function. 58 00:02:13,930 --> 00:02:17,400 ‫The idea is that here, we are more free in terms of that, 59 00:02:17,400 --> 00:02:20,090 ‫the app server is not invoked by the step function, 60 00:02:20,090 --> 00:02:21,600 ‫the step function at the app server 61 00:02:21,600 --> 00:02:23,850 ‫is actually pulling for step functions 62 00:02:23,850 --> 00:02:25,920 ‫to find activities and work to do. 63 00:02:25,920 --> 00:02:27,760 ‫Which is more similar to how 64 00:02:27,760 --> 00:02:31,960 ‫a service called SWF worked in AWS. 65 00:02:31,960 --> 00:02:34,150 ‫So I wanna make this super concrete. 66 00:02:34,150 --> 00:02:36,270 ‫So let's say we want to define a task state 67 00:02:36,270 --> 00:02:38,260 ‫to invoke a Lambda function. 68 00:02:38,260 --> 00:02:40,270 ‫So we're going to define a JSON 69 00:02:40,270 --> 00:02:42,960 ‫and as you can see, the name is "Invoke Lambda function," 70 00:02:42,960 --> 00:02:47,190 ‫the type is task and the resource is Lambda function invoke. 71 00:02:47,190 --> 00:02:48,900 ‫Then the parameters is the function name, 72 00:02:48,900 --> 00:02:50,760 ‫so we specify the function name, 73 00:02:50,760 --> 00:02:53,850 ‫and we pass it on input payload to our Lambda function. 74 00:02:53,850 --> 00:02:57,420 ‫Then we say next, to go to the next state, and the time out, 75 00:02:57,420 --> 00:03:00,260 ‫to see if our Lambda function is timing out. 76 00:03:00,260 --> 00:03:03,800 ‫So what can be states in step functions? 77 00:03:03,800 --> 00:03:05,430 ‫We could have this Choice State, 78 00:03:05,430 --> 00:03:08,380 ‫to test for a condition to send it to a branch 79 00:03:08,380 --> 00:03:09,600 ‫or the default branch. 80 00:03:09,600 --> 00:03:11,480 ‫It could be a Fail or Succeed State, 81 00:03:11,480 --> 00:03:14,000 ‫to stop executing the step function workflow 82 00:03:14,000 --> 00:03:15,960 ‫with a success or a failure. 83 00:03:15,960 --> 00:03:17,300 ‫It could be a Pass State, 84 00:03:17,300 --> 00:03:20,510 ‫simply to pass the input to the output 85 00:03:20,510 --> 00:03:23,650 ‫or to inject some fixed data without performing some work. 86 00:03:23,650 --> 00:03:26,080 ‫It could be a Wait State, to provide a delay 87 00:03:26,080 --> 00:03:27,130 ‫for a certain amount of time 88 00:03:27,130 --> 00:03:30,110 ‫or until a specified date and time. 89 00:03:30,110 --> 00:03:33,160 ‫It could be a Map State, to dynamically iterate steps, 90 00:03:33,160 --> 00:03:37,190 ‫or a Parallel State to begin parallel branches of execution. 91 00:03:37,190 --> 00:03:38,950 ‫What you need to remember from the exam perspective 92 00:03:38,950 --> 00:03:41,630 ‫is most likely going to be the parallel states. 93 00:03:41,630 --> 00:03:43,450 ‫So, and the task state 94 00:03:43,450 --> 00:03:45,360 ‫that I showed you from before, obviously. 95 00:03:45,360 --> 00:03:47,920 ‫So I wanna show you what happens visually. 96 00:03:47,920 --> 00:03:51,530 ‫So we have a execution workflow and this is a workflow. 97 00:03:51,530 --> 00:03:52,440 ‫So we submit a job. 98 00:03:52,440 --> 00:03:53,490 ‫We wait for X seconds. 99 00:03:53,490 --> 00:03:54,430 ‫We get the job status. 100 00:03:54,430 --> 00:03:55,263 ‫Is the job complete? 101 00:03:55,263 --> 00:03:58,750 ‫Yes or no, if not wait again, and so there's a loop. 102 00:03:58,750 --> 00:04:00,450 ‫And when the job is complete, 103 00:04:00,450 --> 00:04:02,300 ‫either you get the final job status 104 00:04:02,300 --> 00:04:04,750 ‫because you completed successfully 105 00:04:04,750 --> 00:04:06,560 ‫or if the job failed, 106 00:04:06,560 --> 00:04:09,010 ‫then you maybe go and deal with that failure, 107 00:04:09,010 --> 00:04:10,900 ‫and all of this go to the end. 108 00:04:10,900 --> 00:04:13,530 ‫So as the execution is started, 109 00:04:13,530 --> 00:04:15,100 ‫we're going to start, submit a job. 110 00:04:15,100 --> 00:04:16,237 ‫We're gonna wait for X seconds 111 00:04:16,237 --> 00:04:18,640 ‫and the blue is whatever is in progress. 112 00:04:18,640 --> 00:04:20,380 ‫Then it goes into several loops 113 00:04:20,380 --> 00:04:22,190 ‫and then the job status is done, 114 00:04:22,190 --> 00:04:24,880 ‫and then we get the final job status and we go to the end, 115 00:04:24,880 --> 00:04:28,660 ‫and this gives us a visual aspect of our step functions. 116 00:04:28,660 --> 00:04:29,950 ‫So the step function is really is here 117 00:04:29,950 --> 00:04:32,070 ‫to orchestrate whatever work you need to do, 118 00:04:32,070 --> 00:04:34,720 ‫to define how your state machine is going to look like. 119 00:04:34,720 --> 00:04:36,530 ‫What your workflow is going to look like, 120 00:04:36,530 --> 00:04:38,550 ‫and I know that right now, this may be, 121 00:04:38,550 --> 00:04:39,870 ‫what the hell is this talking about? 122 00:04:39,870 --> 00:04:40,920 ‫This is very confusing. 123 00:04:40,920 --> 00:04:44,430 ‫I can do all of that in just one Lambda function to program, 124 00:04:44,430 --> 00:04:46,950 ‫but I will show you in the next lecture, 125 00:04:46,950 --> 00:04:48,870 ‫a hands-on on step functions. 126 00:04:48,870 --> 00:04:50,420 ‫It should make a lot more sense, 127 00:04:50,420 --> 00:04:52,940 ‫and then I will show you the whole power of state functions 128 00:04:52,940 --> 00:04:56,040 ‫in the further lecture by talking about error handling. 129 00:04:56,040 --> 00:04:58,790 ‫So I will see you in the next lecture for the hands-on.