Stop Paying for Idle AWS ECS Services: Automate Start/Stop Scheduling

Listen to this Post

In this article, Darryl R., a Cloud Solutions Architect at Ciena, discusses how to avoid paying for idle AWS Elastic Container Service (ECS) resources by automating their start/stop scheduling using AWS serverless components. The key tools highlighted are AWS Eventbridge and AWS Lambda. Eventbridge can schedule actions and react to events, while Lambda can trigger business logic. Together, they enable the automation of scaling ECS services based on events from the Simple Notification Service (SNS).

Practical Implementation

Here’s a step-by-step guide with verified commands and code snippets to implement this solution:

1. Create an AWS Lambda Function:

  • Use the AWS CLI to create a Lambda function:
    aws lambda create-function --function-name StopECS --runtime python3.8 --role arn:aws:iam::123456789012:role/lambda-execution-role --handler lambda_function.lambda_handler --zip-file fileb://function.zip
    

2. Write the Lambda Function: