The key behind designing cost-effective serverless applications in AWS Lambda is by monitoring your cost and resource usage. Unfortunately, CloudWatch doesn't provide out of the box metrics about the resource usage or the Lambda function cost. Luckily, for each execution, the Lambda function writes an execution log to CloudWatch that looks like the following:
REPORT RequestId: 147e72f8-5143-11e8-bba3-b5140c3dea53 Duration: 12.00 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 21 MB
The preceding log shows the memory that's allocated and used for a given request. Those values can be extracted with a simple CloudWatch log metric filter. This feature enables you to search for specific keywords in your logs.
Open the AWS CloudWatch console and select Log Groups from the navigation pane. Next, search for the log group associated...