Step 1: open vi
<<filename>>.sh
Step2: Enter the code as follows
a. Add this code in the first line
#!/bin/bash
b. Connect and run the comment with in the instance
ssh
-i <<keyfile >> ec2-user@<<instance Ip>> << EOF
c. Change user into root
sudo
su -
d. Write the comment you can to execute Eg
aws
s3 sync <<S3 path>> <<local
path>>
e. Exit from root
exit
f. exit from instance
exit
EOF
Step3: Save and exit
from editor
Setp4: provide a
execute permission to created .sh file
chmod +x <<filename.sh>>
Step 5: Run the file
from terminal
./<<filename.sh>>