1 00:00:06,600 --> 00:00:08,039 - Here we'll run through a demo 2 00:00:08,039 --> 00:00:12,206 of just a simple Hello World application in AWS Lambda. 3 00:00:13,140 --> 00:00:15,690 We're logged into the AWS console. 4 00:00:15,690 --> 00:00:19,523 I have gone from here, I have gone to compute, 5 00:00:21,079 --> 00:00:23,911 AWS Lambda, and we find ourselves here 6 00:00:23,911 --> 00:00:25,869 at the Lambda initial screen. 7 00:00:25,869 --> 00:00:27,865 You can see we this because we don't 8 00:00:27,865 --> 00:00:31,315 have any Lambda functions saved yet. 9 00:00:31,315 --> 00:00:34,245 I'm gonna go ahead and click Get Started. 10 00:00:34,245 --> 00:00:38,425 From here Lambda gives us a number of blueprints 11 00:00:38,425 --> 00:00:40,534 for different kinds of functions. 12 00:00:40,534 --> 00:00:42,825 You can see we can start with a blank one. 13 00:00:42,825 --> 00:00:46,875 We have some blueprints for processing Dynamo DB tables. 14 00:00:46,875 --> 00:00:49,208 For getting objects from S3. 15 00:00:50,577 --> 00:00:54,231 You can see AWS Lambda supports various languages 16 00:00:54,231 --> 00:00:56,731 like Python, Node JS and java. 17 00:00:57,951 --> 00:00:59,961 In this example we're going to go 18 00:00:59,961 --> 00:01:02,839 with a blank function and use Node JS. 19 00:01:02,839 --> 00:01:05,060 I'm going to click blank function. 20 00:01:05,060 --> 00:01:06,789 Just for the sake of this demo 21 00:01:06,789 --> 00:01:08,644 I don't want any triggers yet. 22 00:01:08,644 --> 00:01:10,969 So I'm gonna go next. 23 00:01:10,969 --> 00:01:13,552 I'm gonna name this LambdaDemo. 24 00:01:21,219 --> 00:01:24,379 Just give it a simple description. 25 00:01:24,379 --> 00:01:28,546 I'm gonna make sure that I choose the Node JS 4.3 run time. 26 00:01:31,979 --> 00:01:36,149 From here we have the choice of either editing code inline 27 00:01:36,149 --> 00:01:40,316 or we can upload a zip file or pull one out of S3. 28 00:01:41,979 --> 00:01:44,059 For the sake of this demo, I'm just gonna go ahead 29 00:01:44,059 --> 00:01:46,559 and edit the code here inline. 30 00:01:48,319 --> 00:01:51,699 From here you can see that we have a simple function 31 00:01:51,699 --> 00:01:54,109 called exports.handler. 32 00:01:54,109 --> 00:01:57,209 This is how we communicate back to the Lambda service 33 00:01:57,209 --> 00:01:59,109 that this is the name of our function 34 00:01:59,109 --> 00:02:01,630 that we want to execute. 35 00:02:01,630 --> 00:02:04,485 So here for those of us that might not be familiar 36 00:02:04,485 --> 00:02:07,174 with java script, we have a function declaration 37 00:02:07,174 --> 00:02:11,362 which is assigned back to this particular variable. 38 00:02:11,362 --> 00:02:15,029 From here I'm just going to say console.log. 39 00:02:25,881 --> 00:02:28,752 I'm going to output the event variable 40 00:02:28,752 --> 00:02:31,392 that we're capturing here so that we can 41 00:02:31,392 --> 00:02:35,142 see whatever data goes in will come out here. 42 00:02:38,182 --> 00:02:40,397 I'm gonna go ahead and scroll down here 43 00:02:40,397 --> 00:02:44,564 and say yes our handler is the dot handler function. 44 00:02:46,577 --> 00:02:49,007 Now in order for the Lambda service 45 00:02:49,007 --> 00:02:51,827 to be executed we need a role. 46 00:02:51,827 --> 00:02:56,583 I'm gonna go ahead and hit create new role from template. 47 00:02:56,583 --> 00:03:00,750 I'm going to say also call this one LambdaDemoRole. 48 00:03:04,263 --> 00:03:05,763 Policy template... 49 00:03:08,225 --> 00:03:12,392 I'm going to choose simple microservice permissions. 50 00:03:14,043 --> 00:03:15,932 I don't need a whole lot of memory. 51 00:03:15,932 --> 00:03:18,584 This particular demo doesn't require a whole lot, 52 00:03:18,584 --> 00:03:20,152 probably even less than that. 53 00:03:20,152 --> 00:03:23,032 But you can see that we can go up to quite a bit of memory. 54 00:03:23,032 --> 00:03:26,633 One-and-a-half gigs if we need to. 55 00:03:26,633 --> 00:03:28,466 I'm gonna choose that. 56 00:03:29,334 --> 00:03:33,603 We could give this a longer time out if we wanted to. 57 00:03:33,603 --> 00:03:37,903 I think probably 30 seconds would suffice. 58 00:03:37,903 --> 00:03:40,442 10 seconds would actually suffice. 59 00:03:40,442 --> 00:03:42,583 We don't need access to a VPC. 60 00:03:42,583 --> 00:03:44,833 Lambda does give us that option. 61 00:03:44,833 --> 00:03:48,053 If we want Lambda to communicate to services 62 00:03:48,053 --> 00:03:50,763 running in a VPC, we could select one here 63 00:03:50,763 --> 00:03:53,574 if we wanted to, but we don't for this demo. 64 00:03:53,574 --> 00:03:55,584 I'm gonna go ahead and hit next. 65 00:03:55,584 --> 00:03:57,634 Review all of that; that all looks good. 66 00:03:57,634 --> 00:04:01,217 I'm gonna go ahead and hit create function. 67 00:04:02,454 --> 00:04:05,175 There we go; now we have our function. 68 00:04:05,175 --> 00:04:07,154 I can come back here to the configuration 69 00:04:07,154 --> 00:04:09,964 and change those things if I need to. 70 00:04:09,964 --> 00:04:14,664 In the code tab we can modify our code if we wanted. 71 00:04:14,664 --> 00:04:17,964 I'm gonna come up here and configure a test event. 72 00:04:17,964 --> 00:04:22,047 You can see we have a key value pair JSON object. 73 00:04:25,374 --> 00:04:29,264 I'm going to get rid of some of these things here. 74 00:04:29,264 --> 00:04:32,264 You'll see that it's yelling at us about our syntax 75 00:04:32,264 --> 00:04:34,082 but as soon as we fix it. 76 00:04:34,082 --> 00:04:35,312 There we go. 77 00:04:35,312 --> 00:04:37,872 I'm gonna change this key to message. 78 00:04:37,872 --> 00:04:40,289 I'm going to say Hello World. 79 00:04:45,382 --> 00:04:47,842 Down here I'm going to go ahead and hit save. 80 00:04:47,842 --> 00:04:50,642 That will be what we just edited. 81 00:04:50,642 --> 00:04:54,652 That object will be given to this function 82 00:04:54,652 --> 00:04:57,284 at the time we invoke or execute this function, 83 00:04:57,284 --> 00:05:01,403 that object we just edited will be passed in 84 00:05:01,403 --> 00:05:03,712 and captured as the event variable. 85 00:05:03,712 --> 00:05:06,303 Then we're going to console log that here. 86 00:05:06,303 --> 00:05:09,352 I'm gonna go ahead and hit test. 87 00:05:09,352 --> 00:05:11,522 You can see that the output of the function, 88 00:05:11,522 --> 00:05:14,092 the very last thing was said was Hello Lambda. 89 00:05:14,092 --> 00:05:17,162 If we look at the log output we can see here 90 00:05:17,162 --> 00:05:19,553 that this was our message in the code. 91 00:05:19,553 --> 00:05:23,562 Initial execution and then the object that was passed in. 92 00:05:23,562 --> 00:05:27,232 What I'm gonna do is I'm gonna change this a little bit. 93 00:05:27,232 --> 00:05:30,932 Now the callback, this particular function you can see 94 00:05:30,932 --> 00:05:32,792 is also passed in. 95 00:05:32,792 --> 00:05:35,482 The callback is how when we execute that 96 00:05:35,482 --> 00:05:37,771 that's how we inform the Lambda service 97 00:05:37,771 --> 00:05:41,368 that our code, that our function is finished. 98 00:05:41,368 --> 00:05:44,535 We're calling an asynchronous function 99 00:05:45,513 --> 00:05:47,545 so that we can wrap things up. 100 00:05:47,545 --> 00:05:51,712 Here I'm going to, instead of hard coding a message, 101 00:05:52,616 --> 00:05:54,507 I'm going to leverage the message 102 00:05:54,507 --> 00:05:57,376 that has passed in by the event. 103 00:05:57,376 --> 00:05:59,445 I'm going to say callback null, 104 00:05:59,445 --> 00:06:01,615 meaning no errors were given. 105 00:06:01,615 --> 00:06:04,365 We're going to say event.message. 106 00:06:08,305 --> 00:06:12,472 I'm going to say let's save and test this at the same time. 107 00:06:15,317 --> 00:06:17,616 There we go; now our message 108 00:06:17,616 --> 00:06:21,033 that we added to the event.message object 109 00:06:23,585 --> 00:06:27,427 is output here as a result of the callback. 110 00:06:27,427 --> 00:06:31,177 If we go to the logs, we can see that we also 111 00:06:32,025 --> 00:06:35,206 got our console log out there again as well. 112 00:06:35,206 --> 00:06:39,373 We can also see that it took 197 milliseconds to run that. 113 00:06:40,986 --> 00:06:43,986 We were billed for 200 milliseconds. 114 00:06:45,065 --> 00:06:47,565 We only used 8 megs of memory. 115 00:06:48,776 --> 00:06:51,595 That is a Hello World example 116 00:06:51,595 --> 00:06:55,165 of AWS Lambda server list infrastructure. 117 00:06:55,165 --> 00:06:58,646 There were no EC2 instances to maintain, 118 00:06:58,646 --> 00:07:00,727 or create, or worry about. 119 00:07:00,727 --> 00:07:03,496 We just uploaded a function and the AWS Lambda service 120 00:07:03,496 --> 00:07:04,996 handled it for us.