Search code examples
amazon-web-servicesamazon-ec2aws-lambdassm

What is the most efficient way to run scheduled commands on multiple EC2 instances?


Currently working on an environment requirement where we are to push the same file out to multiple EC2 instances running Windows on a scheduled interval. As it stands now, I see a few options and have tried each:

Windows Task Manager: run a basic task on a set schedule invoking the S3 Sync CLI tool

Cons I can see here include: setting up the task on each EC2 instance (there are many).

Lambda: scheduled lambda job that utilizes SSM to run commands on each server in a resource group

Cons: introducing another layer required to execute this task.

Run Command: using an AWS-RunRemoteScript document, run the script (stored in S3) bucket on target instances.

Cons: I'm not positive you can automate these commands on a schedule without adding another layer.

What is the most scalable path forward? Thanks in advance for your help.


Solution

  • Using the Run Command feature of AWS Systems Manager together with either the Maintenance Window feature of AWS Systems Manager or using CloudWatch Events to schedule the execution of Run Command should be useful here.

    If you also tag instances appropriately, you can use the tag targeting feature of Run Command to ensure that all instances run the command (including new instances launched in the future as long as they are tagged).

    /Mats