Aws Ec2 run script program at startup

时光怂恿深爱的人放手 提交于 2019-12-06 07:21:20

A script can be passed in the User Data property.

If you are using the Amazon Linux AMI, and the first line of the script begins with #!, then the script will be executed the first time that the instance is started.

For details, see: Running Commands on Your Linux Instance at Launch

user9575749

What is the OS of EC2 instance?

  1. You could use userdata script at instance launch time. Remember this is just 1time activity

  2. If your requirement is to start the script everytime you reboot EC2 instance then you could make use of rc.local file on Linux instances which is loaded at OS boot time.

If you are running a windows EC2 you'll want to read: https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2-windows-user-data.html

Example:

<script>
echo Current date and time >> %SystemRoot%\Temp\test.log
echo %DATE% %TIME% >> %SystemRoot%\Temp\test.log
</script>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!