As we saw in the previous section, the amount of allocated RAM impacts billing. Furthermore, it impacts the amount of CPU and network bandwidth your function receives. Hence, you need to choose the optimal memory size. In order to find the right balance and optimal level of price and performance for your function, you must test your Lambda function with different memory settings and analyze the actual memory used by your function. Fortunately, AWS Lambda writes a log entry in the associated log group. The logs contains, for each request, the amount of memory allocated and used by the function. The following is an example of a log output:
By comparing the Memory Size and Max Memory Used fields, you can determine whether your function needs more memory or if you over-provisioned your function's memory size. In case your function needs more memory, you...