1 00:00:00,210 --> 00:00:01,290 ‫So now let's talk about 2 00:00:01,290 --> 00:00:03,990 ‫the local capabilities of the SAM framework. 3 00:00:03,990 --> 00:00:05,820 ‫So by using the SAM framework, 4 00:00:05,820 --> 00:00:08,700 ‫you can actually locally start AWS Lambda. 5 00:00:08,700 --> 00:00:11,310 ‫So if you do SAM local start-Lambda, 6 00:00:11,310 --> 00:00:12,990 ‫you will have your Lambda function available 7 00:00:12,990 --> 00:00:15,750 ‫as a local endpoint on your computer 8 00:00:15,750 --> 00:00:18,420 ‫with an emulation of the Lambda framework. 9 00:00:18,420 --> 00:00:19,620 ‫The beautiful thing about it is 10 00:00:19,620 --> 00:00:21,840 ‫that now you can start to run automated tests 11 00:00:21,840 --> 00:00:24,330 ‫against these local endpoints. 12 00:00:24,330 --> 00:00:27,360 ‫You can also locally invoke a Lambda function. 13 00:00:27,360 --> 00:00:29,910 ‫For this, you do SAM local invoke 14 00:00:29,910 --> 00:00:31,920 ‫and this will actually invoke Lambda function 15 00:00:31,920 --> 00:00:33,090 ‫with a payload. 16 00:00:33,090 --> 00:00:34,110 ‫So you will do it once 17 00:00:34,110 --> 00:00:36,780 ‫and then quit after the invocation is complete. 18 00:00:36,780 --> 00:00:39,060 ‫It's very helpful to generate test cases 19 00:00:39,060 --> 00:00:42,930 ‫and in case your Lambda function is interacting with AWS 20 00:00:42,930 --> 00:00:46,410 ‫because, for example, you're doing a API call to DynamoDB 21 00:00:46,410 --> 00:00:49,110 ‫to fetch whatever, re whatever thing from it, 22 00:00:49,110 --> 00:00:52,200 ‫then, of course, you must start your local function 23 00:00:52,200 --> 00:00:55,920 ‫or invocate with the correct --profile option 24 00:00:55,920 --> 00:00:58,170 ‫because you need to say against which environment 25 00:00:58,170 --> 00:01:00,570 ‫you want to be running against. 26 00:01:00,570 --> 00:01:03,120 ‫You can also start a local API Gateway Endpoint. 27 00:01:03,120 --> 00:01:06,390 ‫For this you do SAM local start-API 28 00:01:06,390 --> 00:01:08,850 ‫and it's going to start a local HTTP server 29 00:01:08,850 --> 00:01:11,880 ‫that will host all your APIs and all your functions. 30 00:01:11,880 --> 00:01:13,950 ‫And if somehow you update your code 31 00:01:13,950 --> 00:01:15,240 ‫for your Lambda function, 32 00:01:15,240 --> 00:01:17,670 ‫automatically the functions are going to be reloaded 33 00:01:17,670 --> 00:01:20,070 ‫and your API will be updated. 34 00:01:20,070 --> 00:01:23,190 ‫Finally, you can generate events for Lambda functions 35 00:01:23,190 --> 00:01:26,790 ‫using the SAM local generate-event function. 36 00:01:26,790 --> 00:01:29,467 ‫And to do so, for example, you could combine it with, 37 00:01:29,467 --> 00:01:33,030 ‫"Hey, I want to generate an event for Amazon S3 38 00:01:33,030 --> 00:01:35,370 ‫for putting in a bucket at a specific key," 39 00:01:35,370 --> 00:01:37,470 ‫and then we pipe that input 40 00:01:37,470 --> 00:01:41,850 ‫into the SAM local invoke command that we saw before. 41 00:01:41,850 --> 00:01:44,370 ‫So you can generate sample payloads for event sources. 42 00:01:44,370 --> 00:01:47,280 ‫It could be whatever source really is a source of Lambda. 43 00:01:47,280 --> 00:01:51,300 ‫So Amazon S3, API Gateway, SNS, Kinesis, DynamoDB, 44 00:01:51,300 --> 00:01:53,340 ‫and pretty much all of them. 45 00:01:53,340 --> 00:01:55,470 ‫Okay, so we've seen the local capabilities 46 00:01:55,470 --> 00:01:56,760 ‫of using the SAM framework. 47 00:01:56,760 --> 00:01:57,930 ‫I hope you liked it. 48 00:01:57,930 --> 00:02:00,003 ‫And I will see you in the next lecture.