How to get MONTHLY cpu metrics using AWS Lambda?

0

Hi, I'm running EC2 instance and every month I get CPU usage when I need to. But from now on, I want get CPU usgage every month using AWS Lambda. and my question is, how to set up a monthly date to get monthly usage of CPU?

appearently this is what I wrote at Lambda to get exact month for CPU usage.

"start": "2022-06-30T15:00:00.000Z",

"end": "2022-07-31T14:59:59.000Z",

And I want to make it Monthly. How should I fix it?

已提問 2 年前檢視次數 307 次
1 個回答
1

Hello,

You can make use of the EventBridge in order to schedule the lambda function to run every month using a cron expression.

[+] https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-create-rule-schedule.html#eb-cron-expressions

You can configure an event bridge rule that will schedule the lambda function to run every month to obtain the CPU metrics of your EC2 instance. This can be done by following the below steps:

➞ Open the Functions page on the Lambda console and choose the lambda function.

➞ Under Function Overview, click on Add trigger.

➞ Set the trigger type to EventBridge (CloudWatch Events).

➞ For Rule, select Create a new rule, and then provide the rule name and rule description.

➞ For rule type, choose Schedule expression.

➞ In the Schedule expression field, enter a cron expression. For example, to run the function at 8 AM UTC on the first day of every month, you can use cron(0 8 1 * ? *)

[+] https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/scheduled-events-invoking-lambda-run.html

You can find more information on how to write cron expressions in the below document:

[+] https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-create-rule-schedule.html#eb-cron-expressions

Please note that you would have to configure the lambda function code such that it is able to obtain the CPU usages of the EC2 instance.

AWS
已回答 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南