2021年3月10日星期三

AWS CloudTrail lookupEvents not working with StartTime and EndTime Node js. Getting all events and not filtering events by time

I am trying to extract the AWS CloudTrail lookup events by calling the lookupEvents method provided in the Nodejs sdk. My code is below. I am able to extract the events but from the beginning of the time but not from the dates I have specified.

What should be the format of StartTime and EndTime.

I tried the one shown in the documentation.

EndTime: new Date || 'Wed Dec 31 1969 16:00:00 GMT-0800 (PST)' || 123456789,

 let params = {          LookupAttributes: [              {                  AttributeKey: "EventName",                  AttributeValue: event.EventName              },              {                  AttributeKey: "EventSource",                  AttributeValue: event.EventSource              },              {                  AttributeKey: "StartTime",                  AttributeValue: "Tue Mar 09 2021 00:00:00 GMT+0000"              },              {                  AttributeKey: "EndTime",                  AttributeValue: "Tue Mar 11 2021 00:00:00 GMT+0000"              }          ]      };        const cloudtrail = new AWS.CloudTrail({ region: event.region });      let data;      let count = 0;        console.log(`params are ${JSON.stringify(params)}`)      try {          do {              console.log(`Before method...`)              data = await cloudtrail.lookupEvents(params).promise();              console.log(`data so far is ${data}`);              if (data) {                  console.log(`data retrieved is ${JSON.stringify(data)}`);                  count += data.Events.length;                    if (data.NextToken) {                      params.NextToken = data.NextToken;                  }              }            } while (data.NextToken);            console.log(`The count of Events matching criteria are ${count}.`);      } catch (err) {          console.error(`Error is ${err.stack}`);      }  
https://stackoverflow.com/questions/66572710/aws-cloudtrail-lookupevents-not-working-with-starttime-and-endtime-node-js-gett March 11, 2021 at 04:56AM

没有评论:

发表评论