#100DaysOfWeb in Python Transcripts
Chapter: Days 85-88: Serverless Python with AWS Lambda
Lecture: Creating Lambda test events

Login or purchase this course to watch this video and the rest of the course contents.
0:00 We cannot test this yet in our app because there's one missing link and that's the AWS Gateway API. It will be the API endpoint where
0:10 we can post our payload to and that will trigger the lambda, what we can do though is define the test event here. So I go to configure test events
0:22 and I can define my payload and so here we expect a code one plus one. And let's call this sum
0:39 create and test. And awesome, this works, I got status code 200 and the body said two which is the result of one plus one. Let's try another one.
0:59 Subtract 99 - 19 Create, test, 80. Perfect. One more. 3 * 5.
1:35 And it gives 15, alright one more. Let's check some bad data.
1:56 That's actually interesting, so it turns out that the way AWS Lambda handles exceptions is to return an error message and an error type
2:06 as we've seen here, so we will update our Bottle app to actually look for those keys and that means that in our code
2:21 the exception handling is not really needed. Because this will do the same. so let's quickly update our Bottle app
2:39 to account for this new data.
3:54 So here we check the response back from Lambda for error message and error type. If both keys are there, we define a message
4:03 Lambda function raised a, for example, value error exception and we abort with error code 400 and the message. So now that we have updated this
4:14 on the fly let's do one more scenario. Divide by zero. This should also trigger an exception and yes.
4:32 Then the message would say Lambda function raised a zero division error exception. So this now matches correctly what Lambda will return.
4:44 Of course when stuff works, you get status code 200 and body, and it's the body that we are then interested in. All right, so the next video we're
4:57 going to set up the AWS Gateway API to tie the Bottle app and the Lambda function together.


Talk Python's Mastodon Michael Kennedy's Mastodon