I've created a Lambda (NodeJS) which triggers on a file being uploaded to an S3 bucket. The Lambda uses the ecs.runTask method in the AWS SDK (v2) to then create a Fargate task using a TaskDef which includes two containers to process the file being uploaded. The task is created in an ECS cluster with no services defined.
My issue is that although I'm requesting only a single task to be created I'm always seeing two tasks being created. They both run and produce logs indicating they have processed the file which was uploaded (but I only want to process the file once).
The CloudWatch logs for the Lambda appear normal with only details for one of the tasks being returned (with the taskArn of one of the created tasks).
I've tried removing one of the containers from the TaskDef and get the same behaviour (ie. two tasks, each containing 1 container). I've tried updating the count of tasks to create to 3 and I get 6 tasks started (the Lambda logs show 3 taskARNs). (The duplicate tasks are always created within a second or two of when the first one is created.) If I create the task from the management console using the same setup, it only creates 1 task as expected.
Any suggestions on what the issue might be or how to debug it further would be appreciated.
Switched to using event bridge and step functions and that worked much better. Thanks.