0
votes

I have a number of config files that change a couple of times a month that need to be copied to about 6 EC2 instances. I believe the most efficient way to do this is with a series of scp command in a batch file stored on a windows pc, for example: sudo scp -i "C:\cygwin64\home\Ken\ken-key-pair.pem" \Users\Ken\testcyg2.txt [email protected]:/var/www/html/folder-owned-by-ec2-user/testcyg2.txt

This command works, as long as the owner of the folder is ec2-user. My question is how copy the files to folders owned by the "root" user.

I am not sure this is possible using the aws cli, so I thought I should use the command above, and then a cronjob to take the files from the folder owned by ec2-user, and copy them to a folder owned by the root user.

I put the following command in a crontab, but it does not seem to work: */5 * * * * cp /var/www/html/temp4configs /var/www/html

I even created another crontab using sudo crontab -e, since I was logged in as ec2-user. I do not get any error messages.

Is there a better way to do this, or is there anything I am doing wrong? Thanks!

1

1 Answers

2
votes

A more cloud-friendly approach is to use AWS Systems Manager, which has a Run Command feature. This allows a script to be run on multiple Amazon EC2 instances (and even on on-premises computers if they have an Agent installed).

The Run Command can be triggered on a schedule through CloudWatch Events and it can run the same command on multiple instances, such as any that have a particular tag. It can report back the success or failure of the script on each instance.

The Systems Manager agent is installed by default on Windows Server 2016 instances and instances created from Windows Server 2003-2012 R2 AMIs published in November 2016 or later. Or, you can Install Systems Manager Agent on Windows Instances.