GOTO 2019 • What Does THIS Button Do? Serverless and IoT • Eric Johnson

all right excellent my name is Eric Johnson I'm a service developer advocate for AWS and I'm glad to see you guys here we're gonna have some fun this morning I have a hard fast rule when I do presentations just say you know I never ever do live coding so just so you know about 90% of what we're gonna do today is live coding so we're gonna see with the live code God's due to us and we'll see what happens I know we've had some internet problems but I think we're good but so before we get started I want to just tell you a little bit about Who I am and we'll jump up ahead here also just let me do this real quick so they've got in your application they go to application their ease that's where you ask questions and can rate the session and I would love your feedback and you'll see why today I mean I want your feedback anyway but you'll really see why today I would love to see what you think about what we're gonna build today all right it's a little bit about me I am a senior like you said senior developer advocate for service how many of y'all use service now ok coupley all righty how many y'all would say hey we're experts at service ok yeah I probably you know I would I'm a service da so I'm probably close to it but not really it's it's it's a fun and it's and it's it's a pioneering thing that's going on right how many L do IOT ok all righty so let me give you the caveat here I'm a service guy who's gonna do a little bit in IOT ok I'm not an IOT guy dabbling in service you could go either way so just so you know I am a dad of five and yes that's true I am crazy my wife is a superhero I'm a husband of one that wife I'm a musician and I cross that out cuz a lot of people I'm a drummer I'm gonna knock this sign down just so we're all clear that's going down I am a drummer which is some people say that is a musician and and and I'm a computer nerd I'm a service freak I've been doing service since it came out when it was announced in believe 2014 and I've been playing around with it I've gone through the hard-knock side down through the the ups and downs and so we're gonna talk to some of that today there's a couple rules when I'm speaking and I'm not gonna come off the stage but I will tell you it's a little wobbly so I may take it down as well there's a couple of rules when I was speaking and and it helps a lot and I know you're thinking who are you to make rules well I'm the guy with the mic on right so the first rule is this okay this is any number I want it to be okay there's a good chance I may hold this up and say seven and it's it always said somebody new will come in somebody in the back nope that's a seven because I said seven so that and I do that a lot these are quotes not apostrophes I do this a lot too the other day I was working and someone in the back always waves back and they always use the pinky it's kind of funny and these are thumbs so I will make one finger jokes I'm comfortable with that if it does make you uncomfortable you're gonna be uncomfortable because I make one finger jokes and I have fun with that so we'll have some fun we'll play around today and and we'll get started so let's talk about today's agenda first thing we're gonna talk about what is IOT and service what is it what is it to you second thing we're gonna do is we're gonna talk about the architecture we're gonna build today we're gonna talk about the tools we're gonna build today and then in our demo we're gonna do a couple things we're gonna build and deploy an application back-end okay and we're gonna build and deploy an application for web actually were just going to deploy an application front-end I've already built that okay it's out there and then we're gonna activate an IOT one-click button and I'll kind of explain what that means so for time with time reasons we're gonna we're gonna move pretty quick and hopefully we get it all done so if you have questions please submit them to the app or and we'll try to answer it and I'll be in the hallway I'm also at the AWS booth all day today and all day tomorrow so I'll answer any questions or find someone who can intern for you so all right let's do it okay so first thing we're talking about is is IOT love service okay the idea of IOT and service work together so well now if you're not familiar with service I'm gonna in a nutshell I'm gonna tell you it's it's the ability to manage code or execute code or messaging there's all kinds of things without managing the framework underneath it a lot of times when we think of service we just think of like and I've got this layer icon up here because that's kind of the first thing to think about but serverless is really a lot more than just lambda it's it's it's you start thinking service Li you start thinking of how to execute my code how do I send messages how do I manage this how do i trigger this and with all that I don't want to manage the underlying infrastructure and that's what service provides you now IOT gives gives us this ability to interact with things IOT stands for Internet of Things even one moment here okay and so with IOT we're gonna have an action maybe it's a button click maybe it's a door open maybe it's a someone punches a bag I don't know something like that and it's gonna it's gonna send a message to the IOT hub and this can be several different places ok this can be you know AWS IOT hub it can be something you have running but but basically it's a place that receives these messages it's then gonna trigger a target of some type and then in our world what we're talking about it's gonna be a lambda okay it's gonna trigger a lambda and that lambda is gonna perform a reaction it's gonna do something based on that click so today we're gonna build a feedback application and when you click a button it's gonna tell me how cool I am or uncool or undecided but we're gonna we're gonna go with cool for now okay so that's that's kind of the idea of this IOT love service because with IOT you may have the hardware that you're using you have the buttons that you're gonna click you have the the coffeemaker you have the whatever but you don't have to manage any of the underlying framework so so they work hand-in-hand really well things you can deal with out with IOT man this is just a this is just a list I came off top of my head last night I mean there are so many things you can do you can you can trigger an AWS service I got a buddy of mine that builds his website every time he makes a change he could trigger a whole you know clearing cache things like that all with an IOT button there's you can send an SMS you can send an email turn a light offer on this is very common now you can alert your family start a car or transfer money retrieve your Tesla I got a buddy that's working on pushing a button and his Tesla comes to them okay I don't have a Tesla my suburban won't go anywhere with a button so you can retrieve your key it they have phones you can push a button I the first button I ever got I did that when I clicked it it told my wife I love her I thought that was pretty cool and if you double clicked it told her other stuff it was fun stop sending me messages so you can put your house on vacation anybody have an Alexa okay Alexa's part of our IOT system so I can tell when I leave my house I just did this on Friday when I leave my house is hey hey Alexa put the house on vacation okay when are you leaving I'm leaving now okay when are you back Sunday May okay so she lets the house warm up or cool down I live in Colorado so see I let it cool down and then she warms it back up in time for us to be there that's all based on IOT you can feed your dog you can start sprinklers you can call the police so there's all kinds of different things that could be done and the list is endless so the button we're gonna be using today it's called an IOT one-click or or I'm sorry an IOT Enterprise that it's part of the one-click family and what that means is it's very easy to set up and and I'll actually show you how to set one up today where you can you claim the button and then you assign it some tasks okay and so we could set that up so it gives you an idea of what we're looking at and I've got a couple ease up here and I'll be throwing some of these out later so that's in the box I haven't opened it yet because I said in my Abstract that would be open the box all right so so before we get to coding I want to talk about what we're gonna actually build today and the services Brenna use so we really believe in the right tools for the job okay we really believe in in in making sure that we're being efficient and economic and and effective with our tooling so the tools we're gonna use today are several we're gonna use Amazon API gateway for for us to be able to talk to our voting app with an HTTP like just a website we're going to be using a Tobias lamda that's going to power our compute so that's gonna do our logic okay we're gonna use AWS or I'm sorry Amazon DynamoDB to collect our data we're gonna use I owe to you one click as I talked about before we're gonna use the AWS Systems Manager and you're thinking yourself wait a minute wait a minute this is serverless why am I using a to be a Systems Manager well SSM has this wonderful little thing called the parameter store in it okay and the parameter store is a place where you can store parameters okay it's pretty it's pretty right in the name right it's and so we're gonna use that and I'll explain why in just a minute and we're also gonna use the ADA business amplify console has anybody used amplified before oh you're gonna love it okay you're probably all gonna want to hug me at the end of this amplify is so cool it makes life really easy so we'll kind of climb into that in a minute all right make sure we're good on time okay so this is our architecture we're going to start with so we're gonna build a simple we have a mobile client a web client whatever you can hit it we're not gonna build a mobile app today but you can hit it from your mobile we're gonna all we're gonna connect to the API gateway that API gate gateway is gonna route based on our method so it's gonna if it's a git it's gonna route it to our get lambda if it's a post it's gonna route it to our post lambda and finally it's going to interact with our database behind it okay we're going to we're gonna set up the security and everything it goes behind it the next thing we're gonna do is we're gonna use the parameter store now here's something kind of interesting about IOT buttons okay I can't easily or we're not gonna in this particular session I can't tell it which session to add to okay so I need the lambdas I need the back-end to be aware of what database record I want to work with what my database ID is I can't pass it in for my client I can't pass him from the button so I'm gonna set a parameter in the parameter store that both those lambdas look at so when I get a get request it's gonna go okay what which session by working with okay give me the feedback there and when I'm posting it'll do the same thing it'll grab the parameter from the parameter store so that's why we're going to use that here and finally the last thing we're gonna do is we're gonna connect our iot button and we're going to do that through the console oh so you can kind of see how that stacks I think that's an interesting thing to see so you take your IOT button it clicks it using the AWS IOT one-click service it's gonna then trigger the post the end goal is this we're gonna get this this front-end application that be real time you'll be able to click and tell tell me how cool this is we're gonna and I'm gonna really put you guys to work I would love to see your feedback on this but I still want you to put your feedback in the go-to as well and they have to match so I don't want to see hey it's all cool and then it wasn't cool in there so tell me honestly if it's not cool I want to know but not really so that I do I'm just kidding all right so one other thing we want to talk about is Sam is anybody familiar with Sam okay we got one got great okay – – you guys like it seems cool Sam stands for service application model and it's an a there's several parts to it it's an abstract of cloud formation and so it allows you to do what would take about 20 lines and CloudFormation in about 30 lines and see them and then it goes through what's called the transform that's how here's how it kind of works so a couple things again it's a cloud formation extension it has special service resources you could do functions api's tables layers and applications it supports anything cloud formation so if you you see him you're not limited to Sam documentation or templating you can use cloud formation as well and it has an open specification you can see the link here service to be a study was under common service see him you can read all about it there basically what it looks like is you have a same tempo know if you've seen cloud formation this this looks very familiar but there's some critical things to understand in this division you'll see above there's this transform tag and it tells cloud formation okay this is the same template I need to transform it I need to take these lines of code and turn it into a CloudFormation template for to create a function so you can see here this top one tells it to transform the second section builds the function and it's really interesting you see here where it says events get HTML and then it says the event type is API that's actually going to build an API gateway interface okay that's how we're gonna build this we don't have to go out and set up the API gateway separately Sam is gonna do that automatically for us okay and it's gonna do it we can base it on the path and then the method and then this down here this builds a dynamodb table and that's literally all it takes to build a simple table with an ID of ID and it's an unstructured no sequel table that in dynamo TV so what that enables is this this looks a little different this comes from one of our our examples this becomes that okay and that's the architecture that you see when you're when you're using the CloudFormation template and that's our goal for today so we're going to get started we want some code alrighty and so here we go now I just have two fingers but I fat-finger with the best of them okay so keep up with me we'll probably see some mistakes but let's see where we go on this all right I may have to do some adaption here to get this to work we're just going to end the show here for a moment you guys are gonna see probably my banking information things like that let me close this alright okay so we're gonna just go in now one of the first things we're gonna do let's open my demo workspace yeah now I use Visual Studio code you can do this there's a lot of different IDs that can you can do this on this my preference I also use cloud 9 so we're starting with a very simple I mean it's an empty project right you can see my little squirrel down here for Sam I'm very proud of that alright so the first thing we're gonna do Sam comes with a CLI as well it's not just an abstraction of cloud formation comes with a CLI that allows you to do a lot of things locally and I'm going to show you that today so what we're gonna do is we're gonna do a Sam in it and it's gonna build a default project that is real simple let me blow this code up sorry guys give you I'll see in the back to the big enough for does it need to get bigger okay gotcha I'm sorry how do you install see him that's a great question so Sam see Allah you can do it there brew if you're on a Mac if you're on a PC there's you can be done with pip so it is it is a python-based so you go out to the AWS if you go to service Sam that the link I had earlier it'll show you how to install Sam CLI it is based on AWS CLI so you need to have that installed as well if you're on a Mac I heavily encourage you to use the brew installation for both of those it makes life much easier gets the Python the right version things like that okay so there we go I couldn't remember the hotkeys all right is that better can you all see that a little bigger all right that's doable okay alright so so what we've done here is the Sam invoke it builds us a very basic structure under a folder called Sam app okay and what we're looking at is we have our function which is our hello world function you sigh there it has tests it has a getting an PM ignore it has the actual code and it has a package.json each of the functions are actually treated in in the initial phase that triggers their own applications so you can npm install into a lot of into the team or you can build it so the each functions on its own that's kind of how we how we structure these out you also have an event dot JSON this event is just just there to test if you're doing an API test you have the readme which talks talks to a lot of this and you have the template and this is the same template and we'll talk to that just a second so just to kind of see this working I'm gonna CD into the hello world to the Sam map say map there we go hello world and I want to go ahead and install any dependencies and if our internet is good here there we go so the only dependency we really have we have some stuff for our testing mocha things like that and then we have Axios and you can look inside of the app itself and you can see here and i'm gonna actually just pull this I'm gonna uncomment so you can see these so this is pulling axials which is the library it's a it's an HCP library that does rest calls and then we're gonna hit an IP we're gonna hit a a service that gives back an IP and then what we want to do is we want to go ahead and grab that using an await we're gonna grab that and then we're gonna respond and this is a standard response that we use when we're using an api gateway api gateway in proxy mode and we go into that later or i'll talk about that maybe in the hall will actually just pass the the response back so one of the cool things that we can do here locally is we can do a sam app I'm sorry Sam local invoke and I'm gonna pass it a flag that says no event I I'm not worried about the event right now so it's gonna do that now hang on a second here I'm in the wrong folder there we go it needs to have that template to do the work and I was one folder in okay so now what its gonna do is it actually ran the function and you can see right here is my response message hello world and the IP address we're hitting it from so this is a way for me to run a local invoke then pushing pushing my lambda up to AWS constantly I can test locally I can even go I can say Sam local start API and I can do it with spaces in place here like so and what it's going to do here is it's gonna start a local version of API gateway and it's gonna make that lambda available and you can see right here running on each CP on the root of it because in my template and we'll talk about this a little bit we've got our path hello it's saying I'm gonna run this on one t7 on your localhost let's go let's go see that real quick okay and so we've got an error and the reason we've got an error is because we have to go to the actual path that we want and there you go and now let me blow that up as well so you can see that I'm sure I'll do that so what I've got is a running API and the cool thing here is if I want to go back and change my code I can go back to let's say my app and I'm gonna say hello world let's say hello go to now I'm gonna save this but I'm not gonna restart my service okay I'm gonna go back here I'm gonna refresh that and any delay you're seeing here there there it says hello go to so this allows you to iterate very fast okay you're able to build and work on this and you can you can build local api's and you don't have to push all the time I don't encourage that this is where you run your your test your your regress tests things like that regress the tests and the unit tests that's not what this is for this is for building and building out your service and iterating so alright so what we've got now is we've got this local idea of an API gateway running with a lambda behind it so let's go ahead and start building our application now I do have a cheat sheet so I don't have to type all the code out so you're gonna see me cheat a little bit and I feel totally comfortable with that I'm gonna close some of these out here alrighty so first thing we're gonna do is we're gonna go ahead and we'll stop this service and we're gonna clean up just a little bit so let's go back into hello world and I'm gonna I'm gonna uninstall my Axios because I don't want I don't want a dependency at all there okay so we're not gonna use that anymore so we're gonna replace it okay so now what I want to do we're gonna come back out to the root okay so what I want to do I need two functions right how many – all right you guys are very quiet that I held up to give you a headset yeah I need two functions I'm gonna have one that handles any get requests I'm gonna have wanted two handles any post requests I could put them in the same it's not a big deal I'm through the context of the HTTP or the API gateway call it would tell me hey this is a post this is a push but I like to keep things simple I like to keep them separated okay so let's let's go ahead and build our structure first so the first thing we're gonna do is we're gonna we're gonna move our hello world to and we're gonna call it yet okay so you can see it right here we've changed it out there that's real easy the second thing we're gonna do is we're gonna copy that to post okay so there you go real easy I've got two functions ready to go they do the same thing right now now what we're gonna do is we're gonna update our template okay so let's walk through this template real quick so you can see it now I'll blow the blow the size up here I think it will can everybody see that okay all right so in this original one there's a couple things actually well you know what we're just gonna clear all this out and I'll talk through it on the on the new one so let me grab here my document here oh we got a fail yeah you don't care right now that's because there's nothing there all right so here's our teaching so what I'm gonna do is I'm gonna grab the template we're gonna pull we're gonna pull the whole thing in then I'll walk through and we'll talk through it now what this is this is the same template okay and the same template is what describes our infrastructure if you've ever heard the term infrastructure as code that's exactly what you're looking at okay now my ml tabs and spaces might be a little messed up but the indentions there yamo can be a beast sometimes it's all about spacing it's it's aids anybody who uses you Hamill in here all right how many you're all like no way we use JSON okay all right so okay I love the joke my other data center is a gamble it's funny most people just look at me like I'm weird but that's all right so let's talk to you this real quick so first thing we're doing you see you remember I had this transform so this tells CloudFormation that I'm gonna do the transformation that this is a Sam template and I need to make some changes okay so the second thing I'm gonna do in and in the scope of this exercise we're not too much about this but we haven't we haven't servlets this idea called layers and layers what they do is you can create a layer an external layer and you can share with them with third parties you can share publicly you can keep it private however you want to do and that layer has shared code in it so this is this is the the best practice on sharing code across multiple lambdas in my opinion and so what I'm able to do is I have my AWS SDK and a couple of the libraries that I use in a lie-in in a layer that I have and I use it I in layers are region specific okay so I can use it in either I have a layer out there for us east one and u.s. west ooh those are the two regions I I made me deal with so in this mappings area if you see right here I have a mapping that you can do in cloud formation that I say if you're in US east use this one if you're in u.s. west use this one so that's what you're seeing right here and that's the link to the layers tank the second thing we have is a thing called Global's in sand the idea of Global's means if it appears in the global area apply it to every whatever in this particular example I'm doing functions and api's so I have global settings for my functions of a runtime or time out of three run time of nodejs eight ten layer so and I'm doing a layer lookup so I'm finding that which layer I want and then an environment and there's environments really important because I want I'm gonna be using a table name and a session parameter okay and so I'm gonna pass in the table name and I'm going to pass in the session parameter and that's right here this is a way to make your lambdas you don't want to hard-code stuff in your lambdas right I mean this is just good coding practice you don't want a hard code a table name in here I want to be able to dynamically build it especially as ephemeral as service is you want to be able to use that anywhere I can launch this in two different stacks with no problem it builds the table it puts all the session parameters in everything we need all right the second thing I do is on my API I added some cores settings so that right now I don't care about security anybody's gonna be able to hit this and so I've added my cores to just open it up and that'll apply to each API excuse me but we're only gonna be using one okay the second part of this is these session parameters is the resources so the first thing we're going to do is a session parameter session name parameter this is the parameter value that's getting order disappear ammeter that's gonna hold our value okay this is the lambdas are gonna look it up by the parameter name and they're gonna get back to value that we call our service the second thing we're building is our get function and a couple things in here and then it'll make sense here on the get function I'm telling it's a function type and my properties here's where I find my function so from the template right under the git folder it tells it where to find it and here's the the handler function so it tells it to look for a file called app and a function called lambda handler okay this next thing or what we call managed policies on service we have manners policies you want to be granular when you do services you don't want to open it up to everything so what we're able to do is build these dynamically so we have these manners policies that that in they're listed out when you look at Sam it'll tell you here's all the policies that we offer here's what they do this first one is a dynamo DB read policy it only allows you to read and I'm able to pass it a table name but instead of hard-coding that table name I'm referencing the table that we're building down here okay so what it's basically saying is this lambda can read from this table and this table only and all it can do is read it can also read the same parameter read policy from the parameter that we created right above those are the only two other resources that we need to do you see how I'm locking this down as I go the last thing you want to do is come back and lock everything down build your security into your infrastructure okay that's and with salmon with service in general that's it's fairly easy to do and this uses I am to lock it down and then we see the events that I talked about earlier we have an event it's going to create it's gonna create and this is a logical name just so I know what it is and it's going to create an API on the path of route to say do a get okay so the method is get on the path of route okay so that's gonna create an API gateway now down here we're doing it again okay so you see all the same things this time we're passing a crud policy create y'all know okay all no crud is so I create read update delete and so begin the same table and this one can also just read from the parameter now one question I get all the time is look I've got another lambda arguing another event based on an API if they are the same application that's gonna use it's not gonna create an API gateway in a different endpoint for each one it knows logically hey I'm gonna use the same API gateway for both my functions but once I'm ones get one's a post okay so so that look that that's clear there alright the last thing we're creating is a DynamoDB table to save all our records which is being passed into the lambda stood the environments that we talked about and finally the outputs the outputs aren't necessary they're just helpful okay the outputs gather information that I'm gonna need so one thing this is gonna do is it's gonna give me the API gateway URL that I can get to my front end that it knows where to hit it also gives me the table name in case I need it and it gives me the session parameter name if I want to go in and change that so this is our Sam template lot lot was done here and and you can see we're building two functions a parameter and a table with all the security in place and we're passing all that information into our lambdas okay so you've done a lot with not a lot of lines of code right okay alright so the next thing we're gonna do is we're gonna update our applications okay so the first thing we're gonna do is update our post let me see which one of my grab here yeah we're gonna grab our post app yeah okay so in the post folder is the folder called outlet file called app we're gonna clean everything out of there and we're gonna paste our actual code quick run-through and what this does this loads up the AWS SDK and it's pulling it from that layer that we're including in the template that I showed you locally it will still work it'll pull that layer down so if you're testing locally it'll actually create a local version of the layer we're gonna do a DynamoDB client and this is the simple client there's also a document client that we'll talk about a second this is just a simple client that I needed to put something in there real quick and the work that we're creating an SSM client we're creating some moods and we're tying them to how we're gonna so if I single click I'm happy I'm sorry it's cool if I double click it's uncool if I long click it's undecided all right and then we're also going to grab we create a constant of the SSM params which pulls it from our environment I have this function that his entire job is to update the item and that can be he'll just literally add he'll increment and he returns a promise with that and finally and if you if you're not a node person and you don't understand promise you if you could be a node person not understand promise it can be frustrating sometimes but catch me in the hall and be glad to explain that so here's the main handler this is what lambda is gonna fire when it invokes this lambda and slam to handler based on what the template said so he's gonna he declare some sessions so he goes out and gets that parameter okay he's gonna grab that parameter to know what what table to hit in the data but what what record to hit in the database then we're gonna check if it's HTTP so we're gonna look at the event so an event is passed into the lambda if it has an event body that means it came from our website if it doesn't then it came from one of our IOT buttons this is just a way I'm doing there's a bunch of different ways you can do that but I'm just checking to see that if that's the case then we're gonna parse that body with JSON and we're gonna grab the mood we're gonna tie the click type to the type of mood if it isn't then we're gonna grab there's a different kind of event that comes from the buttons that will grab that click type okay so we set the mood based on our table of moods up there or array of moods is an object last thing we do is we create a parenthesis how you talk to DynamoDB we're gonna tell what table name we're going to interact with the key and then we're gonna pass it the session value for the key and then we're gonna basically it's an atomic counter right so we're gonna add the mood and the value and and if you don't understand this this expression don't worry about it okay this is DynamoDB expressed a little bit out of scope of this but this is how I'm gonna grading with dynamodb with the value and then finally it actually makes that call if the call fails we get back a 500 if it succeeds we get back to 200 and we're good to go alrighty pretty straightforward code the dynamodb might be a little little confusing but that's okay anybody use DynamoDB in the room okay a couple of you so this probably looks kind of foreign what DynamoDB you talked it in JSON objects right so I'm gonna pass table name and some some different things to make that work all right and I realize we are running a little slow so I'm gonna turn up the speed a little bit okay we're almost done at this part and then we can see some other stuff so the last thing we're gonna do is we're going to update our get and this is a much shorter function because his entire job is literally just to read and relay that data so we're gonna go here and let's go to our get app okay okay so his job also same thing this time we're using a document client which the document client kind of does some some cleanup for you on the data coming back from DynamoDB and and then we again ESSM we get the parameter name so there's the parameter name we use that to go out and get the information so what we're gonna do is we're going to we've already got the parameter coming in and we're gonna go out and and this is our function our fetch data function here we're going to use that parameter name to go get the value again just like we did before and then we're gonna do a request against dynamodb and it just says hey using this parameter name or this value I want you to get me the records back tell me what it is and then I'll if it fails we do a 500 so we've got a catch here do a 500 if it succeeds then we return the data back just straight out of there we'll use a data item straight out of there so there's a real simple read from the database it's all I need you to do I've got the private got the permissions everything's there so we're gonna save that so here's where Sam also makes life much easier once we've done this I'm able to to package and deploy my application very easily I'm gonna show you how to do that I'm gonna grab the commands here so we so we can make sure first thing I'm gonna do actually is I'm gonna do a Sam build now if you'll notice here we've got node modules all throughout here okay these aren't needed right these are just for testing okay so I don't I don't want to upload all that but right now our template tells it grab everything in that folder so we've got this thing called Sam build and what Sam build does is he goes through and he makes this dot AWS Sam folder and he grabs only what's needed he ignores there that's what that NPM ignores for you can get just the bare minimum to run your package so if I look under AWS Sam I actually have no dependencies so there's no node modules here so that makes it very easy now I can do a Sam package okay and I'll show you what this command is so here's what Sam package does apparently I hit into there also so Sam package is going to be all I do is I say zip everything up in that folder and put it in an s3 bucket of my choice and I have this bucket out there in the u.s. West ooh and then I say and when you get the results back build me a new template with all that updated and put it in out gamal okay so that's what it's done and you'll see over here if we look we've got a new file called outdent UML now I can do a deploy still using Sam okay I'm gonna say deploy and I want you to use that out template that we talked about okay I'm also gonna pass a capabilities flag these are just CLI commands to understand anytime I'm creating policies I have to tell it I have the permissions the CLI is using my local permissions that you set up with AWS when you said agree W CLI it uses those local permissions those local permissions give me the rights to put that that the the permissions on to the lambdas and the DynamoDB and all that so it's saying yeah I'm aware I'm creating policies and I'm good with that and I'm naming my my stack feedback okay so let's go ahead and hit enter here okay and my default region is in u.s. West to that's the one I've chosen so let's go over here to my management console and we're gonna go to cloud formation and I'll blow this up just a minute here and we're gonna switch over to Oregon and you'll see right here there's my feedback stack and it's being created as we speak okay so what it's creating are my two functions my API gateway my dynamo DB my SSM parameter and it's putting it all together and giving the permissions for all of them to talk and we did that in roughly 20 minutes okay full back into our application alrighty so let's looks we're gonna let that build so while we're doing that we're gonna look at our front-end just so you can so you can see it work okay so front-end I just built a view Jas anybody use view any of you fans okay I use view Jas and amplify okay amplify is an AWS product that allows you to work with front-ends do hosting things like that real quick while this is building I'm going to show you how fast we can do that so what I'm gonna do is I'm gonna go over to my amplify dashboard and I'm gonna open it in a new tab here okay I'm gonna make sure I'm gonna Oregon because that's what I'm working on and I'm gonna create I'm gonna go to my apps and I'm gonna connect an app okay my app happens to be in github and I'm gonna go next and I've already authenticated because I did this earlier so I'm gonna go ahead and choose it and it's going to be oh let's find it feedback here it is feedback web client IOT feedback web client I have links to all this at the end as well so you can get in there and the particular branch that I'm gonna build out of is my master branch I'm gonna hit next and in this I can actually give it build commands this will actually spin up a container and run these commands for you as if you were running straight in the terminal okay so if you have some special things you need to do you just put them right in here luckily for me this works right out of the box because I use a view JSF the kind of fun thing is notice down here it says framework excuse me view it already knew it to do so I'm gonna go next and I can do any appsettings branch master here it is I'm gonna do a save and deploy and you'll see here in a minute that'll flip over now let's check our other one all right so our backends deployed okay here's all our resources and their names okay everything's out there now remember when I talked about that output here is my back-end from our Web API all right so let's let's copy this actually I'll just right-click on that open a new tab okay so it's a null right now and that's what we expected because there's no records in the database right now so this just responds a note our front-end is smart enough to say okay then let's just put all zeros in there all right so now let's wire these up we've got a front end and a back end now my back-end there's what we're gonna look like this is the US East one which we'll do in a second here my back-end here okay that's still building gave me a new IP the front-end building doesn't know what it is so we're gonna have to run one more build in a second so let's go back to our back-end and let's grab that API so we're gonna grab this here and I'm gonna go back to my code which is my feedback code here let me open a new workspace and let's go back to the feedback client all right so what I want to do is I want to take and tell this what the new one is now this is probably kind of a hack way we could probably build on some parameters later to do this but kind of a quick and dirty in my view I know that I've got this URL here and I'm gonna in my views literally just one page so we're gonna update it we're gonna save it and we're gonna do a git commit – mmm new API endpoint and then we're gonna get pushed that okay so that's going to push to my master repo that's resolving it's done what you're gonna see here is on that amplify in a minute you're gonna see that the gonna see this popped it if we go to this site right now it's not gonna work okay it's just gonna come up and say nope nothing's working right now but notice when it's finished here and we'll give this a second to finish then it'll be connected to the back end and we can do some playing around with it so while that's building I want to show you the IOT button here I'm gonna get a couple of volunteers if I could you help me out for a sec toss this to you will you open that somebody else coming at you oh as a bad throw okay just to open it I'm gonna need the botany the buttons back but you keep the boxes okay so all righty okay so we've got a ten-minute warning so we're gonna we're gonna do this but that's okay we're good so next thing we're gonna do is we're gonna tie some buttons in we want to know how do we make this work and you know as soon as this is done building you'll see the front end it's harder than you thought huh yeah it's like whoa I know that's why I had you do it yeah so if you peel the white part build the white part on the underneath where it says rip then that tab will open okay so in order to do that you guys get to see my phone okay so we're gonna pop up my phone here and apparently have messages on it hopefully so on the phone let's go back out so you see it there's a there's an application called IOT one-click database IOT one-click and that is the one we're going to use for this there's also AWS yeah if I grab I may have it but we'll see yeah I got it thanks here push it okay alright so what we're looking at here is we're able to configure everything we want about the buttons okay so the first thing we're gonna do is we're gonna configure the item we're gonna claim and configure these okay so let's grab one of these buttons alright and our and our front-end just built okay so I'm gonna say claim with device ID okay and I'm gonna do a scan with this button up here cuz I have very little moveable room here okay we'll probably just do one for for a rush okay so now I'm gonna have it find that and this can be kinda I'm not gonna lie this could be kind of a pain sometimes so what you do can you guys see what's going on there so you want to move it around till it's the middle if you don't get it a little bit you can manually enter the number hang on a second here if this doesn't we'll just go the ones I have already claimed it's probably too dark let me see if i hadn´t alike oh that's not gonna help is it yeah that was open maybe we'll all righty okay that's alright so here's let me let me talk you through that cuz that's actually the easy part I am falling apart a few days I apologize lapel mic on a non lapel shirt alright so what this does is this is gonna claim the button okay and what that means let's switch back to the keyboard and you'll see on the back end here what that means is it ties the button to your account it's not permanent you can remove that okay ties the button to your account and then you're able to assign it so let me show you what that looks like and and I've got some already assigned so we're gonna go over to the one click okay and we're gonna go and actually the ones I've got our in US east cuz that's what I were gonna use that just a minute and so I can go into my devices and you'll see here I've got two buttons tied in and they're both enabled alright so what I did is I added the buttons the next thing I did is I created a project and that project is called session feedback okay and the session feedback has a template and all this template is it says what do you do in the template I assign what it's going to do and then yes it actually links to the lambda that we created the post Landis you see what I'm saying that not the button itself but the template links to lambda so then what I can do is in the placements of this I can say button one button to both use the same lambda okay so what you've got going on then is you've got the ability to tie a bunch in or have them do different things and but they'll all tie in to do feedback so the final part of that is and in details just kind of show what's going on so now I've got these buttons tied in okay so I create a project then I create a template for what they're gonna do and then I create a the placements you know and I'm sorry we get to walk through all that and timewise getting to us but we do get to see what's going on so let's go back to our application okay there's the one that was broken now it's not broken okay so now we have this full one now I can go to town here click on it a bunch of times and it's gonna do real-time updates okay and so it's dropping data remember that we built this we go back to the US West here here's our table that we built okay when I go in here here's the items and it's just being updated as we go and it's called my session right real simple I cleverly named that right so I was able to build that very quickly to build this session out and were able to tie buttons in now we're not gonna tie the buttons into the ones we've got because like I said wasn't skiing as dark up here we're running out of time but we've got one that's working so what I would like to do is I'm gonna pass out two buttons and here's how it works and you can see as we're going and and I and painfully I do want you to be honest so this is the one they're tied to I was able to update the the Wi-Fi earlier on these so these should be working so you're welcome to go to this website and I have a link for you guys I am literally falling apart up here let me pull up the link for you so you can see it so the link is going to be go to it's a bitly go to – be back so if you want to go to that website and just use your computer or mobile you can see and we'll flip it back well you can see the feedback but let's also candy the buttons a single click is it's cool a double click is it's not cool and a I'm sorry double click is it's not cool and in a long clicking you want to hold it for about 4 seconds will do on decide I'm with roti 2 once just pass that around there alrighty and one of these I have to remember which one here ok alright ok this one should work and I'll pass this you know what I'll come to you guys with this I'm gonna toss this to you ready ok so what we'll do we should be seeing some ratings coming in and I won't know who you are so it's ok alright I decided fair enough that's fair someone just went to town on it that's cool alrighty you guys just click ok undecided so what you've got here is is you have an IOT button and you've got a website that you can do ratings on very quick and there you go go to you to go to Chicago feedback we've got one minute so I'm gonna wrap us up here you guys are welcome to keep looking at that if you want alright so what we did this is what we built out we did accomplish it for the most part the buttons we weren't able to tie in but you see an example of that going on ok and then here's some code for you so IOT if you want take a picture this IOT – FB – back and IOT – FB – front both of these are just repos that have the code in it will also make the slide deck available to you via PDF although most of it is in the code so hopefully that'll work please give me a feedback guys I would love to know how to make this this better I appreciate your time immensely and what I want to do here is whoever has the buttons right now can keep it and I've got a couple more I'm gonna throw out and I'm gonna unclaimed all these and you are welcome to claim them and have fun with them and the meat I don't have one for everybody so I'm just gonna throw some out here ready who help my box openers there you go you get one you get one come away to the back ready oh nice snag okay everybody's got one alright guys thank you for your time I appreciate it enjoy go to

One Comment

  1. Yuriy Yarosh said:

    Well… it's relatively hard to manage proper development environments for this at larger scales.
    So, devops/sre-wise there are way too many risks deploying a per-feature based dev env.

    June 26, 2019

Leave a Reply

Your email address will not be published. Required fields are marked *