Optimizing Python Script Execution on ECS with Apache Airflow: Cost-effective Strategies

0

"I have multiple Python scripts stored within a Docker image, each with its set of input parameters. My goal is to execute these scripts on Amazon Elastic Container Service (ECS) as required. Inside the Docker image,

I have the following scripts:

• ex-tract_satellite_data.py

• calculates_ndvi.py

These scripts rely on various input parame-ters like 'sensor' (e.g., 'sentinel2') and 'config_file' (a YAML file with start and end dates, etc.).

Currently, we're using ECS and EFS to run these Python scripts. The scripts are executed using ECS tasks, and the required files are mounted in EFS. To further streamline this process, we're considering automating the ECS task runs using Apache Airflow. However, we're facing cost concerns with AWS Managed Apache Airflow (MWAA), as it lacks the option to pause when not in use.

Considering this, we're exploring the most cost-effective way to manage this workflow. We're contemplating whether to set up our own Apache Airflow instance on an EC2 instance or continue with AWS Managed Apache Airflow. Are there any alternative solutions or best practices for managing this process efficiently and economically?

Your insights and recommendations would be greatly appreciated."

1 Answer
0

Hi,

A more cost-effective solution will be to use EventBridge to schedule a Lambda that will start / stop your ECS tasks: see https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-run-lambda-schedule.html for a tutorial.

An intro to this service is here: https://aws.amazon.com/blogs/compute/introducing-amazon-eventbridge-scheduler/

You cannot manage the sophisticated DAGs possible in Airflows. But, your use case seems simple: so, it should fit.

Custom events like the one you will publish to trigger the lambda : $1.00/million custom events published. See https://aws.amazon.com/eventbridge/pricing/. You have to add also the costs of running the Lambdas when starting/stopping but here also it should remain very small.

Best,

Didier

profile pictureAWS
EXPERT
answered 8 months 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