Turn off the aws app runner container whenever the cpu usage is 0

0

Hello Everyone, I have created a app runner service where i have deployed my docker container. Now i want to turn off the container whenever the cpu scales down to 0. And whenever the request coming to the aws app runner provided api i want to turn on the service again. Can you guys suggest me how can i implement this architecture??

Suman
已提问 1 个月前105 查看次数
2 回答
1

Set Up CloudWatch Alarms: Create a CloudWatch alarm that monitors the CPU utilization of your AWS App Runner service. Configure the alarm to trigger when the CPU utilization drops below a certain threshold, such as 1% or 0%.

Create Lambda Functions: Turn Off Function: Create a Lambda function that stops (or scales down) the AWS App Runner service. This function will be triggered by the CloudWatch alarm when CPU utilization scales down to 0%.

Turn On Function: Create another Lambda function that starts (or scales up) the AWS App Runner service. This function will be invoked whenever a request is received by the AWS App Runner provided API.

Set Up CloudWatch Event Rules: Turn Off Rule: Create a CloudWatch Event Rule that triggers the "Turn Off" Lambda function when the CloudWatch alarm enters the ALARM state (i.e., when CPU utilization drops below the threshold).

Turn On Rule: Configure a CloudWatch Event Rule that invokes the "Turn On" Lambda function whenever a request is received by the AWS App Runner provided API.

Integrate with AWS App Runner: In your "Turn Off" Lambda function, use AWS SDK (such as boto3 for Python) to stop or scale down the AWS App Runner service. In your "Turn On" Lambda function, use AWS SDK to start or scale up the AWS App Runner service.

Testing and Monitoring: Test your setup by simulating scenarios where CPU utilization drops and requests are received. Monitor CloudWatch metrics, logs, and alarms to ensure that the automation works as expected.

已回答 1 个月前
  • This answer sounds plausible but is incorrect. For example, there are no CloudWatch Events posted when a request is received by the App Runner API that can be used to scale out the function. Nor can you manually adjust the scale of an AWS App Runner Service.

0
已接受的回答

Hello.

Instead of deleting the container when the CPU usage reaches 0, I think it is better to delete the container when the application process is finished.
In other words, I think you should create an asynchronous API like batch processing.

If you can create a configuration like the one below, I think you can create an asynchronous API like batch processing.
a

profile picture
专家
已回答 1 个月前
profile picture
专家
GK
已审核 1 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则