我正在尝试从我的 Python 脚本运行 AWS Instance Scheduler 的 scheduler-cli。我试图通过 boto3 做到这一点,但可能不支持它。由于我能够通过 Windows 命令提示符运行 scheduler-cli,因此尝试使用 subprocess 从 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 凭据,但不确定如何为子进程设置这些凭据。
谢谢。
我能够通过从 os 包运行 scheduler-cli 命令来解决这个问题,因为 AWS 的 API 尚不可用。
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()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句