簡體   English   中英

運行 python 腳本的 AWS EC2 用戶數據不起作用

[英]AWS EC2 User Data to run python script is not working

我正在嘗試在 EC2 Linux 機器上運行 python 腳本。 我想要的只是在實例的每次啟動時它應該運行這個名為 my_file.py 的 python 腳本/文件。 它在我的 ec2-user 目錄中。 我也嘗試過手動運行,運行命令“python3 my_file.py”后效果很好。

我一直在關注如何從這篇文章https://aws.amazon.com/premiumsupport/knowledge-center/execute-user-data-ec2/中寫入用戶數據

我的用戶數據代碼:

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
python3 /home/ec2-user/my_file.py
--//--

我沒有看到這個文件在這個實例啟動時運行。 我試圖查看 /var/log/cloud-init-output.log 文件,但由於權限被拒絕問題而無法打印它。 在這里附上一張圖片。 不確定是什么問題,或者我在這里遺漏了什么。 謝謝。

在此處輸入圖像描述

您可以在腳本的開頭使用sudo -i ,否則您必須以 root 用戶身份使用腳本來執行命令

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM