我正在尝试从我的Python脚本运行AWS Instance Scheduler的scheduler-cli。我尝试通过boto3进行此操作,但可能不支持它。由于我能够通过Windows命令提示符运行scheduler-cli,因此尝试使用子进程从python脚本运行scheduler-cli但出现错误。以下是代码段和错误:
cmd='scheduler-cli create-period --name "testperiod" --begintime 07:00 --endtime 20:00 --weekdays mon-fri --stack instance-scheduler --description "7 AM to 8 PM Monday to Friday" --region ap-southeast-2'
try:
subprocess.check_output(cmd, shell=True).decode()
except Exception as e:
print(e)
print("Could not create period.")
我得到的错误如下:
subprocess.CalledProcessError: Command 'scheduler-cli create-period --name "testperiod" --begintime 07:00 --endtime 20:00 --weekdays mon-fri --stack instance-scheduler --description "7 AM to 8 PM Monday to Friday" --region ap-southeast-2' returned non-zero exit status 1.
该命令在Windows Shell中正常工作。也许我需要在脚本中以某种方式为aws提供凭据,但是由于我要遍历不同的帐户,因此需要提供不同的sts凭据,但不确定如何为子进程设置这些凭据。
谢谢。
答案 0 :(得分:0)
由于AWS的API尚不可用,我可以通过从os包运行scheduler-cli命令来解决此问题。
cmdschedule='scheduler-cli create-schedule --name testschedule --periods testperiod --timezone Australia/Sydney --stack teststack --description "6 AM to 8 PM Monday to Sunday" --region ap-southeast-2'
try:
myCmdperiod = os.popen(cmdperiod).read()