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??

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.

답변함 한 달 전
  • 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
전문가
답변함 한 달 전
profile picture
전문가
GK
검토됨 한 달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠