Search code examples
amazon-web-servicesaws-lambdaamazon-ecsaws-fargate

AWS Lambda invoking Fargate task


I am new to AWS and experimenting with AWS Lambda and Fargate. I have a long-running process that I have defined as an AWS Fargate containerized task. This task is triggered using ecs.runTask(taskParams, callback) api call from an AWS Lambda function. The Lambda function is triggered by a notification of a file uploaded into an S3 bucket.

You can now configure your AWS Lambda functions to run up to 15 minutes per execution. Previously, the maximum execution time (timeout) for a Lambda function was 5 minutes. (Source: Amazon)

My question is, does ecs.runTask() run the task asynchronously inside an on-demand container without the lambda function that triggered it waiting for its completion? Does that explain how the lambda function is no longer bound by the task running time? Is this a recommended approach for long-running processes where we don't want an ECS instance just around?

Finally, what is the difference between ecs.runTask() and ecs.startTask() api calls?


Solution

  • asynchronously inside an on-demand container without the lambda function that triggered it waiting for its completion?

    Yes. Lambda will just start it.

    what is the difference between ecs.runTask() and ecs.startTask() api calls?

    startTask can be only used on EC2 launch type and requires you to explicitly choose which EC2 instance to use for your task. Can't be used for Fargate and allows you to launch a single task.

    runTask can be use for both EC2 and Fargate launch types. When you use runTask ECS decides where to place your tasks, e.g. which instance. Also, you can run multiple copies of a single task at once.

    There are probably more differences, but I think the above are the key ones.