Every true sysadmin has been in this predicament — “I need to run this command on a bunch of machines.” The typical approach is to create a for loop, and run the command serially. This works well, but if a) you have tons of hosts, or b) the command takes a while to run on each machine, you may be looking for something a bit more efficient.
Here’s an example that gets a list of hosts using aws-cli, and restarts httpd on them. In your case, update the command and key path as needed.
HOSTS=`aws ec2 describe-instances --filters "Name=tag:env,Values=production" "Name=tag:Name,Values=web-frontend" --query "Reservations.Instances.PublicDnsName" --region "us-east-1" | jq -r .`
echo -n $HOSTS | parallel -vv --gnu -j +3 -d " " -I HOST "ssh -i ~/my-key.pem -l root HOST 'service httpd restart'"