Hello guys, welcome to the 18th session of create custom Alexa scale using AWS lambda function tutorials for beginners. In this session, we will see how to use Cloud watch to check logs or JavaScript and when we are creating back at each error logs will be shown in console type of browser. But what in case of lambda function, it does not run on client side. For this we need to use Cloud watch, which is also part of AWS. So let us open AWS console. Search for cloud watch.
Click on logs. For each lambda function AWS create log group I have created several lambda functions so here it contains logs for all of them. Here we are interested to watch logs of lamda that we have created. I have used second demonium for lambda is selected. When we deploy lambda function first time it will automatically create log stream within log sorted by descending event time. Select the first year at all logs.
It includes time in message. Currently we have not added any logs so it only contains details of request stat and I have removed version one changes from a rescue. Let us modify our lambda function to add logging display greetings handler. Here I am adding all slots in logs so we can check for its values. Convert Jason to string using stringify expand fabric Which handler here we have obtained a lot value from request as well. Now, I am adding any undefined property here.
So it will generate an error. Let us save it and deploy lambda function. Now tested in the emulator. Here we got an error as expected. Open log groups again after deploying new log stream will be created, so, let's select it by clicking expand collapse all links we can expand or collapse all logs on this page. Here you can see that it contains log details.
And here added details. For some errors. It will also add call tech, which is similar to the console of the browser. We have added slot details in the log for only display greeting. But what if you want to log all of JSON data that received by our lambda and response generated by it for these we need to use interceptors. Gil will provide some methods for creating interceptors.
Use add request interceptors method and pass function which will get request and will up and response. Now let us add title tags. We can identify this log uniquely and log request and we'll have Jason data using string five And use add response interceptors method. It will similarly GET request and develop and response. So let's just copy above function a bat title. And here we need to pass a response object.
Let us deploy it again. Open tested and call a risky again. Open new block stream. Here is JSON data for request thanks Once. This will be very helpful to you. Now let us see what we have learned in this session.
To watch logs and error we need to use Cloud watch. We can use add request interceptors and add response interceptors to generate logs for each request and response. In those methods, I have just loved data, but you can also perform some other kind of operations before or after call handlers. Thanks for watching this video. If you have any doubts, please feel free to contact me. Have a nice day.