I'm trying to use aws logs start-query function, but I need something more dynamic than start-time/end-time (with unix timestamp). Like last 5 minutes or something like that. Is this possible?
CodePudding user response:
AWS CLI doesn't offer such possibilities like "last X minutes" for logs regardless of function you use to find logs. But start-time and end-time is fully flexible way to get logs - you just need to pass proper values. It means that you can create own script doing exactly what you need, i.e. it could calculate start and end time and just pass them to to start-query function.
Example of simple calculation of start_time and end_time in bash:
#!/bin/bash
declare -i start_time
declare -i end_time
declare -i last_minutes
declare -i last_millis
end_time=$(date %s)
last_minutes=$1
last_millis=$last_minutes*60*1000
start_time=$end_time-$last_millis
echo "$start_time"
echo "$end_time"
so you can invoke this script passing number of last minutes and it will calculate start_time and end_time. Then you just need to invoke proper command you need, e.g. aws logs start-query --start-time $start_time --end-time $end_time
instead of printing start_time and end_time. You can introduce other options in the script depending on your needs as well.