skip to Main Content

I have an android app that uses AWS lambda as a backend to fetch data – which usually takes a few seconds of execution time per request.

I would like to be able to fetch data and cache it at the end of the month if there is still free execution time available, however, I could not find a way to access that information inside a lambda function. Is there a way to do this?

2

Answers


  1. You need to have your Lambda function send logs to Cloudwatch. Then, whenever it executes, you get something like:

    REPORT RequestId: c9999f19-0b99-4996-8dea-94c9999999de  Duration: 5495.59 ms    Billed Duration: 5496 ms    Memory Size: 128 MB Max Memory Used: 82 MB  Init Duration: 306.78 ms
    

    You can then export the logs and using whatever tool you like get your monthly total.

    Login or Signup to reply.
  2. if there is still free execution time available

    You cannot directly do that, need to perform cloudwatch log aggregation as told by @Dan M, but the most ideal way would be to always set an alarm and notification once your overall execution time( across all functions ) exceeds your desired value

    It is a very straightforward approach using cloudwatch alarms :-

    • You need to choose metric based on dimension which is called as across all functions to be able to view aggregated execution time for all functions in that region. Check how to view all functions
    • There are 2 types of metrics Invocation and performance metrics, you need to focus on performance metrics, for these metrics you need to consider their average statistic
    • Now create cloudwatch alarm for Duration metric ( under performance metric) and add sns rule when ever alarm breaches your desired value

    According to Docs for duration metric

    The amount of time that your function code spends processing an event. The billed duration for an invocation is the value of Duration rounded up to the nearest millisecond.

    Docs for creating cloud watch alarm

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search