Install ssm agent on ec2, therefore we can run any shell cmd on this ec2.
I. install ssm agent on ec2:
1.login fcgi ec2(ec2 you have, save as a AMI is better), run sudo su
2. mkdir /tmp/ssm
3.cd /tmp
4.yum install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm
5.status amazon-ssm-agent (RHEL 6.x); sudo systemctl status amazon-ssm-agent (RHEL 7.x)
6.check logs:
/var/log/amazon/ssm/amazon-ssm-agent.log
/var/log/amazon/ssm/error.log
II. create new IAM role for ssm.
1.change to IAM console, create new role, select AmazonSSMFullAccess and other you need. the created role is: dcs-asg-ssm-iam
2.take FCGI ec2 change the IAM to dcs-asg-ssm-iam.
3.restart FCGI ec2-instance.
4.check logs in /var/log/amazon/ssm/ folder.
III. Run commond on ec2.
1.ec2 consloe->Run Command->Run a Command->AWS-RunShellScript
2.you will see FCGI instance ID, choose it if there are many IDs.
3.Command*: insert your shell, as cd /var/log/amazon/;mkdir deng/
4.click run
5.ssh fcgi ec2, you will see the cmd exe in this ec2, as folder "deng" created
Finish.
网友评论