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
asked 12 days ago68 views
2 Answers
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.

answered 12 days ago
  • 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
Accepted Answer

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
EXPERT
answered 12 days ago
profile picture
EXPERT
GK
reviewed 12 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions