App 2025 Episode 2: Express Workflows for quick-running processes

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay so if you've got the closed captions turned on you would have seen all that hi everybody welcome to episode 2 of AB 2025 apparently I still don't know how to work the mute button on my microphone today we are going to cover a new step in our app for any company and that's Express workflows for quick running processes these are AWS step functions Express workflows and these should be the default in your new architecture so even if you have a business process that right now is one lambda function one an AWS lambda function you should consider wrapping that in an express workflow and I'll explain why that gives you a little more functionality as that process grows so rather than having that fragility and the temptation to go insert some of your business logic into your lambda function you can continue to refine that workflow with your business analyst and for more on this you can see some of our previous episodes of the serverless office hours with AWS step functions on the AWS channel those are also available with links in the chat so today we're gonna go back and review the architecture where we got to so far what we've put up there we're gonna introduce AWS step functions Express workflows we'll compare these with step functions standard workflows so that you can have a basis or a framework for deciding when to use which and which one's more beneficial for you I'm gonna give you this Express workflow event loop pattern that we sort of touched on on the first episode and we're gonna talk about how to put the events back on to the event bus when you're done running your Express workflow and then finally we're gonna build all this together again in Visual Studio code using Sam CLI and with one exception we have to build one lambda function today but it's gonna be sort of a universal one that gets reused and we'll talk about that later and then of course we'll do Q&A at the end QA as we go ask whatever questions you have I'm just happy to be here I'm happy to have you with me so let's get started all right so if you remember last time we're talking about any company which is just a generic software as a service provider and we went through Benelli's events storming process to generate eventually some bounded context and three micro-services customer operations and billing will return to this right now today we're gonna work on building out this subscription expired process the business process and we're gonna start very simple as you might when you're like founding your company like a startup and then it's because it's an entire workflow you have the flexibility to iterate in the additional functionality and definition that you need later but if we look at this architecture remember we talked about an Amazon event bridge custom event bus sort of running left-to-right through time and events go on to the bus business events like those that we defined and at that point a workflow or a business process or a number of them should pick them up and respond to them according to their own needs right so the bus and the producers don't have to know about downstream consumers they just put the event onto the bus and whoever's interested in it picks it up the general pattern that we're gonna work up to is gonna be to listen to that event via a rule run it through a workflow and put it the completed event back on to the bus it's that simple but it's powerful this is gonna be just almost all of your application right so it's a very powerful workflow that we can build through now I promise we talked a little bit about the difference between standard and classic workflows so I'm sorry standard and Express workflows I always do that they're gonna be so mad at me I just dropped some links here in the chat channel the first one is the launch blog for express workflows the second one is standard versus Express workflows if you click on that one I'm gonna bring this down on screen for you look at this there's a couple key areas that I want to highlight for you so probably the first one if you've been building a lot with standard workflows you know that they're very durable and they can run for up to a year that's a very powerful construct when you need it when you don't need it it just is more than you need right so that's one of the first differences is duration and Express workflow will run for a maximum of five minutes before it times out now that's what we see here on this first line for maximum duration what you're also gonna see is the concurrency is wildly different on these right so out of the box your default standard workflows can support a start rate of 2000 workflows per second whereas Express flows Express workflows support over a hundred thousand per second so you can see that as your business grows and you start getting more and more events put onto the bus more rapidly you've still got plenty of capacity to consume those and to kick off your workflows pricing is different and this is another one of the links that we put in the chat here you see AWS step functions pricing the classic workflow standard workflows pricing is based on state transitions so as you move through states in your workflow the Express workflows pricing is much more similar to AWS lambda it's based on the number of executions you run and their duration so it's a it's like a sum of gigabyte seconds and that is a declining price for gigabyte seconds that's the same measure that we use for AWS lambda functions as well so this should be pretty familiar so you pay $1 per million requests and then six cents per gigabyte hour for the first thousand gigabyte hours a gigabyte hour is a 1000 sorry it's one hour of one gigabyte of allocation and that allocation is flexible your your work flow takes however much it needs and we'll see an example of that in the logs and that's in increments of 64 megabytes and then an hour is an hour right but that's split off just like AWS lambda functions are today into increments of 100 milliseconds don't ya etj geek is right I'm just gonna I'm just gonna say the wrong thing over and over but I will always correct myself that is my solemn promise to you we got execution history as well so if you saw us for the launch of the AWS step function support in the AWS toolkit for visual studio code you see that we brought visualization from the console into that extension that's really powerful for Express we're close because the AWS management console by default doesn't provide this you can still track your workflows and how they're executed by enabling logging we'll go through that later today I'll give you or later in this session I'll give you an example of how to configure that and the code for configuring that along with the permissions and you also see one of the links that we pasted it in the chat here step functions logs gives you the required iam permissions that you're gonna need to enable for cloud watch logs on Express workflows and then another key one if you saw our episode on on step functions on Tuesday this week we went specifically over service integrations and we talked about the three service integration patterns request response run a job which is the dot sync or sorry job run which is that sync and call back which is not wait for task token patterns Express workflows don't support those two last patterns only standard workflows support those two patterns so that's the key difference in general what does this mean for you right if you're building your application and you're looking at your business process and you need to know okay which one of these do I pay in general I would suggest that you start with Express workflows and say this is how I'm gonna build this and then you look for reasons why you have to move off of it okay so let's say you have a manual step in there where you dispatch an approval email to you know a director level manager that has to wait for a callback and that could take obviously longer than five minutes well Express workflows are no longer gonna suit your use case if you need to use that callback pattern not necessarily for people but for other service implications or if you want to run synchronous jobs like AWS batch AWS glue that we reviewed in service integrations that may not be a good use case for you to run Express workflows but when you start out of the box I would suggest that you just say okay all my workflows now our Express workflows until proven otherwise because you're gonna get the benefits of increased concurrency you're gonna get the benefits of generally lower pricing at the volumes and it you know it's a good way of just getting in getting that pattern set okay so looking in the chat here I don't see any questions yet I'm just gonna keep driving on alright so let me go back to this pattern real quick the way that we get an event is via event bridges rules and let me pull up an AWS console AWS management console window for us here I love it when it logs me out even though I checked and then you get to jump back in there you know what I mean we adapt we're flexible we overcome let's bring this in here and blow it up a little hopefully this time in the right window okay so if you remember last time we can also go into vs code and look here we had built a couple like we sort of skeleton doubt our microservices and we built an event bus declaration in a SAM file and all we did was named an event bus and then capture its location in this SSM parameter to use for later so if we look at this back in the AWS management console we've got our event buses and we have our custom event bus for any company right so at this point I've got a schema discovery enabled on here we can we'll talk about that at the end of this session if there's time if not we'll talk about it in a separate session dedicated to this but we've got rules and at this point we don't have any rules on our account a rule is just matching an event and poking a target so that's the first thing that we need to do to get going so to do this we're gonna go back into vs code and I'm gonna drag this is a little crazy it'll make sense later I'm gonna move this function out of here into the eventbus and I'm gonna move the events folder along with it so that when we're working here inside our customer microservice all we have right now is a SAM template and that's all we need so let's clean this up a little bit we no longer have a function so we no longer have Global's in fact we no longer have outputs in fact we no longer have much of anything at all right so the first thing we want to do is create a rule and this rule I'm not sure if it's in me yeah it is good cloud watch a Vince rule this is the BS code extension for cloud watch so it's an AWS events rule we're gonna name this expired subscription rule because remember we said back in our diagram we're working in this customer relations bounded context to handle subscribed subscriptions so let me just do some cleaning up here make sure we don't have any questions okay good now what do we need in here properties description is optional but let's grab one much like Eric Johnson who was on just a little bit before me I was up late working on this so I'm I'm gonna steal some code as we go from myself last night today me is very happy with last night me right now for running all this ahead of time we're gonna give ourselves a little parameter here just to make things easier on ourselves so that we have some logical references we'll call it event bus name give it a default this is just a standard cloud watch parameter we give it the default of any company to match but it also lets us listen to things further down here the event bus name is what that's supposed to reference in this case rather than pull it from the SSN parameter that creates it's just beyond the scope of what we want to do right now but you can insert this here in your pipeline whenever you're deploying by providing a value there for today we're gonna be hard coding a lot of things that aren't relevant to express workflows in particular but first we got to learn how to kick this off so we have a source this is just a top-level field in an event and if I can show you a custom event can look like anything it can be any JSON object right so we're gonna have source in here as calm that any company and you can have things like detail type anything you want there are standard formats for AWS provided events those schemas are available in the event bridge documentation which are here again in those links but for your event you put whatever you want in there and you refer to it however you want so in our case we're gonna grab anything that comes from our our company app here and detail type we're looking for subscription expired events and all this means when we go back over to this event is it's gonna come in looking like this right that's it that's all we got to do okay now and you'll see I've got some sample events later that won't match this will have some that come in from another source they don't get handled we'll have some that matched a different type of event they don't get handled but any event that comes in that matches these this pattern that we're specifying here will trigger our target and so we're not gonna deal with the detail field right now Eric knows that I like to state my defaults all right so for a target we're gonna have to give it the AR n of a workflow the ID for the rule itself and a roll AR n which is the role that the rule runs as so it's the role to invoke our workflow so we're gonna have to pause right here for a second we need to create a workflow it's gonna need its own role and at the same time we're gonna need to create a role for the rule okay so how do we do all this stuff's getting complicated right that's okay we can handle this we know that we need a workflow so let's call it expired subscription workflow we'll come back to that we know that we need a role for that so let's call it expired subscription role and then we know that we need an in book role right so as we build these out we're going to be able to pick up the the events coming across our custom event bus that match that pattern that we defined right so we're gonna build these out now we know from previously that we can use the AWS it's we're going for here step function state machine as our type and I'm gonna go ahead and cheat and just pull this in because that's gonna be a lot more effective than me tight and all this for you and we're gonna look at what we built we're gonna need to change this definition here in a second but let's start with this so the only difference between this and a standard workflow is this state machine type Express and this login configuration that we talked about earlier I'm gonna pull that out because it can complicate things but at this point here's what we have we have a publish events function that we're gonna get to in the end let's pull that out as well [Music] we can take this down just cleaning this up for y'all bring it back to look like that in a minute so if you want to know where all this stuff is gonna live there's a repo link there in the chat for you I'll clean this up and push it up for afterwards but we're starting again with this basic step function state machine configuration we give it a name we need to provide this role still so let's build that this is the difference between a standard and an express where closes state machine type and we give it a definition string which at this point didn't need to be a sub in there I deleted the wrong things so let's see all right let's see what happens let's see what happens next and then we need to provide a role for this as well I gotta tell you as I build here I didn't sit down and ride all of these last night you know what I mean like you gotta build up a library for yourself whether you do it in github with gist's whether you pull from your previous projects you've got to build up a library this this stuff is complex right so you see this role that we just dropped in here this we have to have it has to be able to assume the role this is all related to logging so we can skip this for now take that out and bring it back later it still has to have a role right and then we have the invoke workflow role so I'm actually gonna comment some more things out here I think I got a little bit out of order on you all I'm gonna comment out this rule and just get down to the simplest thing we have which is an Express workflow no logging configuration a single pass state and then it's required role right so let's check here we're in the customer service we've got our AWS profile set says it's a valid template we'll see and do our Sam deploy guided so for this we'll call it app 20 25 customer I deploy the US east - it's very Ohio keep that default value keep all the defaults for the rest of this and then we'll see where this goes and we can go back into the console once it's done I gotta tell y'all last night I was going back and forth on the the I am permissions in the policy to set up logging for the Express workflows and it was I beat my head against the wall for a little while and it was 100% my own fault because ultimately after a long time I went back and I read the actual documents they were right there right there with what I need okay value of property definitions string yeah so it doesn't like that modification that I made let's uh here's my definition string real quick you mean just second to clean this up y'all it's like that magic incantation that I can never quite get right I was right I was right it's I think it's that let's try this again nope you don't need to guide it anymore we've already saved everything oh yeah detail I've done this before if you if you attempt to create a stacking on the first time it doesn't go you have to delete that stack cloud formation now we can see what happens here but yeah always read the docs even when you think you know what you're doing that's when I get to right that pride of thinking uh I put this in place before it's fine everything's fine narrator it was not fine so and then we read the docs the docs get us there and won't be alright okay hooray successfully create an updated stack now I want to show this to you real quick in the console go over here to step functions we've got this and you see this looks a little different right because it's of type Express so we don't have our visualization here that we had before like I mentioned earlier that means ultimately we're gonna have to get logging turned on I'm sorry we do have this visualization it's over here what you won't get is the visualization of the execution where you walk through at each state getting your your green states so we still have the visualization that we expect but not during execution but so we have it here we can start an execution it won't really tell us anything because if you haven't turned logging on but it helpfully does tell us to see the execution status and history enable logging on your state machine alright so we got a few things that we need to do here we've got that in there we need to enable logging we need to finish the rule we need to change the rule so that it can invoke the workflow we need to finish the state machine let's do the logging configuration first so I'm going to mark this here for logging configuration here's how you enable logs for your Express workflows there's this highlighted block here that's a login configuration block this is document it's in the step functions logs link that I gave you over there so we'll unhighlight that this won't work right now because we don't have permissions to write out to these those permissions need to come into our role here so we're gonna add a policy down here this is the part where I told you I had to learn how to read again last night because I'm hard-headed let's get to here we need to we need to give it a log group too so let's do that first we have to have somewhere to log so step one put your login configuration here we've told it we're gonna write to this log group so we need to create that log group right we set a retention to be seven days so that they'll age out that's optional and now we need to create the necessary policies again I'll go back over here and prove to you that I can be taught by bringing this logs page down here it's got a handy little configuring login and even a handy little iam policies for logging to cloud watch logs which might look like the exact thing that I needed last night right so we can bring that in as a policy and it will look like this okay so there's a little bit of a difference here I'm like a super lockdown kind of person technically all of these will work with star but these allow you to limit your actions even further so we can only do them to our log group so that's what I've done here so the steps to get logging enabled I guess first would be to create the log group second create the login configuration so that your workflow rights to that log group and third add this policy available from the docks into your role and I need to give it I knew something didn't look right there their statement policies all right here we go that looks better to me okay so Sam deploy again see what happens here y'all if this doesn't work on my dislike I just throw everything in the air and go home cuz I fought with this I'm just kidding this is gonna be fine because I read the docs see so we see it's created our law group for us here it's modifying the role that our step function is running as we just gotta wait for that and so once this is done we'll do another execution so that you can see how the login works there all right super update complete hooray see when you read the docs all right so if we go back here and now we go back into our state machine we can see that logging is defined and we've turned on all and included our execution data and we have this cloud watch logs group over here so now we can start an execution and this time we see that we have exactly what we'd expect right execution started past state entered past state exited execution succeeded and in here you have some metadata around timestamps length of execution etc right so you can understand how your workflow is executing all right so we've got our logs enabled now we want to go back what was next y'all like forget okay now we need to create a so this gives us an AR n right because it's a workflow so that's gonna be what we invoke we'll give it a name but we still need to create a role which allows it to invoke the the Express workflow now the good thing about this when I copy and paste this when it's gonna be a lot shorter let's see here so the service here isn't region specific it's events that Amazon AWS in your assumed role policy document and policy again you just give it a name you allow it to start execution with a reference to our workflow right so it's a very tightly limited policy that we're creating for this rule realistically you can move this back into your events bus account because remember we're talking about like an organization with multiple accounts and then just add workflows to this policy as you go that's a that's an organizational thing and how you structure your rules I'm doing it here so that we can see all the changes that we've made together but this is a iam policy that's going to allow us to invoke our step functions workflow so now we can go back here and we can create our rule we can uncomment all of this because we have everything we need right so we went through before we gave it a name we assigned the event bus which is the custom event bus that we created last time in our event in the JSON object we're gonna filter for exact matches on these fields it's enabled sorry I write my mo this way for our AR n we're gonna use the expired subscription workflow right so whenever you reference a step functions workflow the AR n is what's returned ID we got to give it a name we'll call it expired subscription workflow why not mr. creative over here and then for the role this is a little bit tricky we need to get the dot AR n attribute on that role okay so this is not the same as the AR M before so what this means this target block here you can have up to five targets in a rule each target specifies the AR end of the resource that it's gonna invoke gives it a friendly name for you to see in the console and then gives it an I am role AR n that it executes as so if we redeploy this we're looking over here no questions yet I know this is like a little bit esoteric so hopefully having the code to look at later is gonna be the real value in this one the the example of having everything pulled together let's wait for this so what this is doing is wiring up our event bus to look for any event that matches that pattern we gave them and then when it finds it to invoke our workflow so we'll see that be defined here and while it's doing that we can at some point we're gonna need to kick off the definition of a state machine that always fails for me the first time I executed I need to uh I've got weird settings y'all alright this is still going so we're gonna use this to define our actual workflow and we'll start with a parallel state and end with a past state and so what this is simulating here remember we're talking about the business event or the business process process an expired subscription so you want to like for our example we're gonna say do two things at the same time one disable all the resources that that subscription owns but not necessarily delete and to email the customer right and then at the end you want to put the processing complete back onto the bus so we'll come back to this in just a second and now we see that that deployed so we can go back to the event bus and refresh and now we have this rule here right listening on the custom event bus for subscription expired events and we can go in here and we see the event pattern is what we would expect and we see the target is what we expect we've got this state machine and a matched event right so let's go back here let me find my events because I know you don't want to see me type JSON objects let's open this up and here in the root so these are just sample events and you'll notice that the event format everything gets converted into pascal case which is the best case don't at me Shree sorry I just joined can you give a brief introduction of what we're doing today yeah welcome thanks for joining us we are hooking up Express workflows from AWS step functions to our custom event bus to handle short running tasks of less than 5 minutes so we're showing how to create a rule that filters events and triggers a workflow and then at the end we'll put that workflow back on to the bus but as I was saying if you look at our events here they're in Pascal case the best case we have some that match we have some that don't match we have some that match based on detail type and we have some that don't match based on detailed type right so we're actually gonna have five events here and only two of these match what we're looking for so we want to test this out and we want to make sure that what we're expecting to happen happens that is we put five events in here to two of them get picked up by the rule and so we should see two step functions workflow executions so if we go back over here to cloud watch and this log stream may not be the one that we get right this is we got one log stream for entries right so we come back over here and there's a there's a console command that you can use CLI command big CLI fan AWS events put events and the entries we'll be this file that we just created that's not gonna work because I'm in the customer folder there we go AWS events put events entries file put them in stock JSON okay and then this will run that command it'll give us all right good zero failed entries they all went in we put five events on the bus and so now if we go back over here no surprise we don't see that there but aha we've got two new log streams right and if we look at these we've logged out in our past state the data that we were provided and we see that this matched on detailed type subscription expired and source calm down any company which is exactly what we wanted to see so our rule is set up to filter based on that type and based on the source right but at this point we're not really doing anything with either with our work flow or at the end of it what we want to do to complete the pattern is do some of that processing we were talking about and then put it back on to the bus so real quick let's go back we can close this and we can go back to our work flow that we talked about we're gonna define this work flow with process cancellation and we'll start there that's going to be a parallel state so we're gonna give it two branches state one and state two and we'll start at you know suspend Rhys all resources and send expiration email right and so these are just standing in for actual workflows that you would do whether it's another workflow or a lambda function or something like that we just want to suspend these here with pass States or let these stand in here so we'll call that that not that and I like my ends like that I always hit safe if you were with us on Tuesday you know that about me I mess that up every time and that's okay and then once both of these are complete we're going to publish to a vent bridge all right this would be a past state you don't need to put any of that in there we don't need to deal with any of this and then this will be an end state right okay so let's see happy happy happy we've got no red we like no red let's visualize it here all right and just as we expect this is more analogous to like it's a simple workflow but it's a real workflow right so if we're handling this subscription expired event in that customer bounded context what we want to do is suspend all of that customers resources send an expiration email to them which hopefully encourages them to come back and reactivate their subscription right and then once those two things are done we want to publish to event bridge a new type of event saying that we've completed processing this so let's take these states out of here and we're gonna drop them into our actual workflow definition under states right and these I need to do some whoops bear with me while I do some dude that was not right I do some you call it housekeeping I don't know branches it's probably a better way I could have formatted this right but I don't actually know if it'll stay if I lead it this way anyway we're almost done so be brief publish to event bridge okay - I have like extras in here what's happening y'all does anybody know I don't know I don't know what's going on here all right no that's correct those match states match published remembrance matches next publisher Bembridge pull these back okay not the most interesting part of this demo let's deal ya maligning that's right yeah I'm aligning it's still my favorite language it's not my favorite language there's still better than JSON so again we can update now we need to go back to our customer directory and deploy this again last week we talked about in the real world this would be a separate pipeline in a separate account right because you would have the customer team working on the customer micro service it would not be in the same mono repo like we uh missing process cancellation state is not reachable it's it's because I failed to update some stuff I know how to fix that we're just keeping them in the same repo for convenience here so that you have one reference to go back to and look at all this at once and once that finishes failing to update will redeploy it and then the final step that we'll need to look at here is getting this final event back on to the event bus as of today step functions does not provide a way to natively like do a service integration back to event bridge to put final events on the event bus the you can handle the state transition events which are AWS native events on your default event bus that already in your service account but remember we're looking for the business events on our event bus that's why we created a custom event bus we see this is uh this is updated already we can go back here and put some more events on there they all get picked up they all run through go back here and look at our definition again and now we see just as as we'd expect we've got these nice more realistic but simple business process diagram here and again we look we've got these top two rows because we filtered those five events down to two matching events you can see now this is a lot more information for us to look at you will want to configure the amount of logging that you have whether you want to log transitions or not whether you wanna log only errors and warnings etc I just want you to see what's possible and see the the amount of data that you can capture here all right all right all right all right so last things last we need to put some events back onto the bus everybody on the bus right that means we're gonna need to take our state machine here and instead of publish to event bridge as a pass state let's make this a lambda task state publish to event bridge and true and then we can get rid of some of this other stuff like this resource is defined parameters we'll have to give it a function name I'll have to give it a payload we can this is again the JSON path notation that we've talked briefly about we're gonna do a whole episode on the step functions series dedicated to input path output path and result path so at this point we can just grab this state we're gonna have to do some yem aligning again but it'll be quick I promise cuz we're only replacing this line alright or this state alright I know somebody all out there like don't bother and I'm like you don't understand the power my OCD okay in here a couple things are gonna have to happen right we're gonna need to create a lambda function or wire this up dynamically right so now is where we go back to that magic incantation I've given you earlier where you substitute everything in here and when we do that remember sub takes two arguments the first is your template string and the second is a map of values that you want to substitute and so in here we're gonna want to give it something like publish to event bridge we'll give it a variable that we want to replace right we're gonna add a lambda function here publish event functions they are in and for the payload let's just take that subscription ID that we've been passing through and pass it in as well so what this means is we're gonna create a variable at the top level and we're gonna populate that with the value of detail dot subscription ID from our original event that we passed in that we created over here alright so we've got this detail subscription ID field well since we gave it a name there we have to give this a value we have to get this value from somewhere and there's a couple ways that we can do this look at the time we got 14 minutes I'm gonna do this the right way I think we've got 14 minutes to do this the right way [Music] we're gonna change this to publish events function AR in which is going to be another parameter I say the right way because it's my belief that this should live with the event bridge custom event bus because it's a it's a function that's gonna get reused over and over you don't want to rebuild it in every micro-service it's a simple function that takes any event and it throws it on the bus all right that's all it does so it takes like an event bus argument it takes an event argument and then it puts B on a and then it returns happy days right so it doesn't do any processing filtering anything else it's just sort of a stopgap until hopefully we get a service integration for AWS step functions and events in event bridge that'd be great wouldn't it the AR end of the lambda proxy function don't want don't want function name just want function type string today we're probably gonna go back once we create this and just copy-paste that default in there let's see so this is what I was doing earlier let me close up customer here whenever I dragged that whole HelloWorld function into here that's what I was doing just putting that there so that we had time to do this the right way so while I'm going over and pulling this over something to remember if our state machine is going to call that lambda function it needs to have I am permissions to invoke it as well so after all of these policies we're going to give it another policy which allows it to invoke lambda function and that'll just be ref whatever we call that up top publish events function AR in yeah good ok so now it can invoke that function now I'm going to close this stuff for a second we've gotten everything out of our state machine that we want it looks the way we want it to look so we're going to close this I'm going to close this sample event because we built several events so we're going to close this these events are just going to stay the same we've got them that's wonderful and then this is our customer template so we're gonna get rid of that as well now we need to add a new resource here which is going to be our publish events function code URI publish events so we need to rename this it's gonna do app that lambda handler which if you haven't seen it's already in here I'm gonna replace this code in a minute runtime nodejs yes it needs a policy that allows it to put events on to this event bus but we already know we can refer to that dynamically and that's all it needs to be able to do right just needs to be able to put events onto our event bus and we'll probably want our publish events they are in the AR N of who y'all itchy and the function cuz we're gonna need to pull this in oh oh so meadow what just happened there a missing space it's always a missing space okay super so now I'm gonna give you some simple code in here let's get rid of all of this and again I wrote this last night I am NOT a JavaScript developer so if you don't like my JavaScript you're probably right but all this does brings in the SDK we don't actually have to run through the whole package JSON thing because that's gonna be in the environment give ourselves a new event bridge client we receive an event we parse out that subscription ID we create this is this is a new event so when you call event bridge dot put events you need a an object with an item called entries which is a list of events so this is a single event this is a list of one item of event and in this case we'll see this won't match our existing rule right because this is expiration processed and we were looking for a subscription expired previously so it's okay we're not going to be in a loop here just give it some information that we want we pass that subscription ID in the detail and then we just log out some information so that's all we need to do here pretty simple pretty straightforward simple lambda function just takes that event that we give it throws it onto the bus nope no wonder I was already where I thought it should be let's make sure we got a nice decent Sam file here we got seven minutes left I think we're gonna get this done it I love to push this right up to the end y'all knowledge let's deploy this to perform at our unrecognized resource types server this function oh you know why I deleted that transform in there I also didn't Sam build I'm surprised the edj geek didn't catch me and call me out on that one you can do it that's I'm trying buddy I'm trying I'm going I'm going let me get this transform that we need put that pretty little transform right there and now we can do Sam build which will package up our app nicely for us and then Sam deploy which will take it up load it up load the code create that lambda function for us with the rule we got six minutes left I think it's almost guaranteed at this point that I probably missed something in I am so let's see let's see how this goes for us I can't be everywhere I have faith in your brother you can be actually I don't need you to be everywhere I just need you to be here with me here with me right just kidding buddy I appreciate you so we're waiting all right super that rolls done function functions done stacks updated everybody's happy we got this AR n for the event bus and here's the one we really need right this is the AR end of our lambda function we're gonna hard code this for today obviously not the right way to do that the new Sam deploy process is awesome it is it is it would be more awesome if twitch respected those back techs that you were trying to do to highlight but you know this is the world we live in we make do with what we get with what we can all right so this is event bus we're gonna close all this stuff out we're gonna go back to customer remember in our template we said that we were just gonna put that default value right there for the publish events function AR n now at this point maybe edj knows the answer to this he is Yoda I need to get Sam deploy to update this I think the right answer it's gonna be to run Sam deploy guide it again to recapture this parameter because this is a new parameter that we're giving it but we put it in here and we've tried to wire it up we got five minutes left so y'all it's getting serious it's getting serious right now let's see what we got here we don't have any lambda functions we've just got this let's run Sam deploy guided failed to parse template while scanning a simple key ah look at that let's say it's a hard return there I don't know how that happened things happen all right okay yeah may that be our hiccup yes run it again I am running it again - G works - it does but why would I use that hey picked up our picked up our new parameter here so look at that save that wait for the change set to be created this will only take a minute because we're just uh the part you are editing is behind the caption so hard to see and help debug by the way you know you can move those captions around just grab and move them on the screen or if you click the settings cog you can collapse them to a box you can hide them altogether if you just prefer listening to my soothing baritone tell a dad joke three-legged dog walks into a bar and says looking for the man and shot my paw it's all got it's the only dog dog joke I got we are done deploying here so you didn't know that one you didn't know live out in the great American West and you don't know that joke I should have said saloon maybe you heard it that way before so we think we've wired all this up we got three minutes left let's put some events on the bus and see what happens first we probably want to be in the correct directory - put some events on the bus and tada alright five events outbound y'all and we know already that we should see to be picked up so we go back over here nothing's really changed for this we come back here expired subscription process we go back to our logs and let's see 14:57 two executions that's great Joe that's great execution failed I told you I was gonna get it we got all the way into our publish to event bridge state the Jason path specified for the field cannot be found in the input detailed type subscription is fired set a region details subscription ID dot detail dot subscription ID okay why not should be in there I see it details subscription ID maybe it's something because I put the that - there makes things go crazy instead of a I bet that's what it is I'm gonna use my last minute here with y'all to change the - to an underscore and see if that's it if I don't get that done the since it was working last night it will work we also did some filtering here with like pushing stuff in there so doesn't necessarily mean that that was going to get done correctly so here's customer past state subscription ID detail dot subscription ID I've done here this is one of those it's gonna be interesting to debug hmm well it actually matches what I had before so let's take a look at our see if the other one did the same thing this is about anyone 9f9 e execution failed jason path dot detail dot subscription ID specified for the field could not be found in this input I see why do you see it do you see it it's a it's a collection of events that's why so I'll need to manipulate this a little bit and see where I went wrong there it may be just at some point I didn't it's because it's um we added that parallel state so two states come back out and both of them have that field we didn't set where the result paths went to one quick workaround would just be to put the zero there and take the first copy that's not the right answer so I'm gonna fix this up the right way push it to the repo the repo is here in the chat it's three o'clock I want to thank you all for joining I know this was a very deep dive I'm gonna write this up and step through this in parts as well split these up into videos but again the workflow that we covered was picking up events from event bridge passing them to an express workflow and then putting them back on to an event bridge event bus thank you all for joining I'll see you next Tuesday for AWS step functions
Info
Channel: Serverless Land
Views: 985
Rating: undefined out of 5
Keywords:
Id: pdc6oorQ3lE
Channel Id: undefined
Length: 62min 0sec (3720 seconds)
Published: Thu Apr 16 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.