1

Is it possible to capture the startTime and endTime of execution of lambda functions along with parameters that were passed to it ? I couldn't find any state-change event configurations that could be configured to send events when lambda function starts/terminates?

A crappy alternative is to record parameters & start time in database when the lambda is being invoked and have the lambda update the endgame as final step before it's completion. This appears prone to failures scenarios like function erroring out before updating DB.

Are there other alternatives to capture this information

3
  • If you set CloudTrial trail to log Data events for lambda, you will be able to get invoke event in CloudWatch Events. Not terminate though. Commented May 21, 2020 at 23:41
  • 1
    CloudWatch Logs records the START and END of a Lambda function invocation. You can log the parameters as needed. Commented May 22, 2020 at 1:32
  • What are you going to do with that info? If the purpose is to just record then I agree with @jarmod above, START & END are already captured in CloudWatch, you'd just have to log the event and that's it. Commented May 22, 2020 at 17:03

1 Answer 1

1

aws x-ray may be a good solution here. It is easy to integrate and use. You may enable it aws console.

  • Go to your lambda function/ configuration tab
  • Scroll down & in AWS X-Ray box choose active tracing.

Without any configuration in the code, it is going to record start_time and end_time of the function with additional meta data. You may integrate it as a library to your lambda function and send additional subsegments such as request parameters. Please check here for documentation

Here is a sample payload;

{
  "trace_id"   : "1-5759e988-bd862e3fe1be46a994272793",
  "id"         : "defdfd9912dc5a56",
  "start_time" : 1461096053.37518,
  "end_time"   : 1461096053.4042,
  "name"       : "www.example.com",
  "http"       : {
    "request"  : {
      "url"        : "https://www.example.com/health",
      "method"     : "GET",
      "user_agent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/601.7.7",
      "client_ip"  : "11.0.3.111"
    },
    "response" : {
      "status"         : 200,
      "content_length" : 86
    }
  },
  "subsegments" : [
    {
      "id"         : "53995c3f42cd8ad8",
      "name"       : "api.example.com",
      "start_time" : 1461096053.37769,
      "end_time"   : 1461096053.40379,
      "namespace"  : "remote",
      "http"       : {
        "request"  : {
          "url"    : "https://api.example.com/health",
          "method" : "POST",
          "traced" : true
        },
        "response" : {
          "status"         : 200,
          "content_length" : 861
        }
      }
    }
  ]
}
Sign up to request clarification or add additional context in comments.

1 Comment

@learningMyWayThru by default no - you need include x-ray library, define your parameters and send it manually. it will be shown in the subsegments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.