1

I am trying to automate generation of a report based on an insight query, every Monday for the past week. I need to run an insight query every Monday as a cron job. Could someone guide me on how I could automate setting the end time and start time to be last week's Friday 12:00 am and end time to be last Thursday 11:59pm.

const insightsQuery = {
        endTime: moment().unix(),
        startTime: moment().subtract(7, 'days').unix(),
        queryString: myQueryString
        logGroupNames: ['/aws/lambda/MyLab']
    };
return logsClient.startQuery(insightsQuery).promise()
        .then(({ queryId }) => { 
do something
}
Th F Sa Su M Tu W Th F Sa Su Mo 
   <---------------->        |
                             |
                            Cron job is ran every week on Monday to generate a report for the last week
raosa
  • 119
  • 1
  • 8
  • 1
    I think what you have is pretty close. Under the assumption that it's always running on a Monday, couldn't the `startTime` be `moment().subtract(10, 'days')` and the `endTime` be `moment().subtract(4, 'days')`, then you use [`set()`](https://stackoverflow.com/a/34762651/2869332) to use either midnight or just before midnight for your start/stop times? – Zulfe Feb 07 '22 at 12:35
  • How to run insights query every 15 min every day? – Biju May 06 '22 at 10:28

0 Answers0