EC2 Linux实例-在实例重启时运行python脚本



谁能指出我做错了什么?我希望我的两个python脚本在EC2实例重新启动时运行,我使用AWS EC2 Linux实例&云9

我明白了编辑用户数据需要改变,以实现这一点,但我没有成功,目前我已经尝试:

Content-Type: multipart/mixed; boundary="//"
MIME-Version: 1.0
--//
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"
#cloud-config
cloud_final_modules:
- [scripts-user, always]
--//
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="userdata.txt"
#!/bin/bash
python script.py
python script2.py
--//--

但是这没有用

我参考了这篇文章- https://aws.amazon.com/premiumsupport/knowledge-center/execute-user-data-ec2/

script.py和script2.py在ec2实例重启/启动时运行

最简单的方法是将脚本放入:

/var/lib/cloud/scripts/per-boot/

这假设cloud-init在实例上运行,这是使User Data脚本工作的魔力。Ubuntu和Amazon Linux ami默认安装。

有关实例启动时运行作业的示例,请参见:在完成任务时自动停止EC2实例- DEV Community

最新更新