API to find the number of instances run by hour - AWS - amazon-ec2

I am looking for API that can return number of instances that run during the course of the day for each of the hour.

If it was my task, I would create a php script that runs in cron job every hour and record EC2 instances information (Running number of instances a part of that) in the database.
Then just query the database to with the right parameters.

Related

AWS lambda or AWS batch to delete rows from dynamo DB based on certain criteria

I have a requirement where I need to delete records based on criteria it doesn't need to be real time, the records are stored in dynamo DB. Can AWS lambda be scheduled ex run every day # 11pm can I package a cron job or is it better to go with AWS batch only worry with batch is it has more overheads.
Thanks
If your criteria is time then the best option is to use the Time To Live (TTL).
DynamoDB TTL feature delete a records after expiry.
TTL is useful if you store items that lose relevance after a specific
time. The following are example TTL use cases:
Remove user or sensor data after one year of inactivity in an application.
Archive expired items to an Amazon S3 data lake via Amazon DynamoDB Streams and AWS Lambda.
Retain sensitive data for a certain amount of time according to contractual or regulatory obligations.
AWS provides details in this document.
If instead you have more complex criteria, you could use Lambda as you requested, however creating a Lambda function alone won't be enough.
In fact Lambda need always something to kick it off, like a cron job.
AWS recommends to use CloudWatch to schedule Lambda runs. Relevant documentation can be found in the tutorial "Schedule AWS Lambda Functions Using CloudWatch Events"
This process includes the following steps:
Create an AWS Lambda Function to log the scheduled events. Specify this function when you create your rule.
Create a rule in CloudWatch to run your Lambda function on a schedule.
A rule would look like:
aws events put-rule
--name my-scheduled-rule
--schedule-expression 'rate(5 minutes)'
Verify the rule checking that your Lambda function was invoked.

Scheduling tasks in spring boot one after another

I am trying to have scheduling in my spring boot application, I am already using scheduler with cron expression but the problem is that I have about five scheduler in which I need to schedule the first three scheduler tasks to run once in a day and the rest of which runs after executing these two tasks.
The problem is that when the first scheduler running for some time the second one scheduler starts when its time reaches and it makes misunderstandings because both tasks are using the same database as well as same table. I want to process a record only once e.g if any scheduler process a record will not be processed by any other scheduler that day. So now I want to schedule these tasks in a sequence when the first one completes the execution then the second one will be starts and so on.

How to run cron job at users time zone using spring boot

We have users from all over the world using application. Our requirement is to run cron job at 12 am daily at users time zone and only for users in that time zone.
How can this be achieved using spring boot??
In #Scheduled notation you can pass Zone but only single time zone so you need to manage it with custom logic.
I believe your user record has included with time zone so to order to achieve it, You will need to set the cron job to run every half an hour(cover all time zones to include + 1/2 an hour), Get all timezones which has midnight then get users in those time zones to run logic for them..
You have to convert all the cron job times (12 am) in the user's time zones, to the equivalent times on your server, by adding or subtracting hours to compensate for the time difference. With the server time zone equivalent of the cron job times, you can schedule all the cron jobs.

Aggregate timeseries data over various timeframes

I have a question about how to aggregate time series data that is coming into DynamoDB.
Currently energy usage data is coming into DynamoDB every 30 seconds per device. The devices are also spread across many timezones.
I want to show the aggregate energy usage over one hour, one day, one month, and one year.
I know one way that I can do it is run a Lambda on a 1 hour cron job that takes all of the readings for the previous hour and adds them all together and then records that in a different table in.
At the same time in that cron job the Lambda can check if any devices timezones just had their day end, and if so batch up the previous 24 hours for into a single day reading.
The same goes for month, and year.
But something tells me there is a another, better, way to do all this (probably using some otherAWS service which I am not thinking of)
Instead of a cron job, you can use dynamoDB streams.
In this case, when a record comes into your data collection table, it can kick off a lambda function that updates your aggregate tables. That will allow you to get more timely updates into the aggregate tables. The logic for what hour/day/month/year your record gets aggregated should be in that lambda.
Also, I’d use a cloud watch event instead of cron...

Oracle Scheduler - can a single job be both event based and time based

Hi I am new to Oracle Scheduler. My question is - Can we give both repeat interval and event condition in the Schedule object for a single job?
I have this requirement in job scheduling - A job should run at a scheduled time, but only if a certain event has occured.
For eg.
Job1 should run
- at 10 am every day
- but only if same job from yesterday is not running anymore. (This I gonna figure out based on the table entry.) So the event gonna be a cell entry say 'ENDED' in the table job_statuses.
Would be easier if I can give both info in the same job. Else another approach I gonna try is - Schedule the job based on time. If the earlier instance is still running , reschedule the job based on event. But this looks clumsy.
Thanks in advance.
Mayank
I'd encode the condition in the PL/SQL of the procedure itself. i.e. it runs at 10am every day, but the first thing it does is check if the previous job had finished successfully.
What you could do is create 3 jobs
EVENT_JOB
REPEAT_JOB
ACTUAL_WORK_JOB
EVENT_JOB and REPEAT_JOB just start ACTUAL_WORK_JOB. If that is already - or still - running, you get an error on which you can react accordingly.

Resources