python - Connection with boto to AWS hangs when running with crond -


i have basic python script uses boto query state of ec2 instances. when run console, works fine , i'm happy. problem when want add automation , run script via crond. notices script hangs , waits indefinitely connection. saw boto has problem , people suggested add timeout value boto config file. couldn't understand how , where, added manually /etc/boto.cfg file suggested timeout value (5) didn't help. strace can see configuration file never being accessed. suggestions how resolve issue?

there chance cron environment not close enough interactive shell of login prompt.

paths , things .boto or boto.cfg files not found or in same place in cron's environment. also, on systems (ubuntu) cron runs dash , not bash, things different.

if croning script, try source /etc/boto.cfg file or set aws environment variables make sure it's using proper settings

better yet - read them in python script making portable , not reliant on env. vars.

from configparser import configparser, nooptionerror, nosectionerror boto.s3.connection import s3connection  try:    config = configparser()    config.readpf(open('/etc/boto.cfg', 'rb'))    aws_seckey = config.get('credentials', 'aws_secret_access_key')    aws_keyid = config.get('credentials', 'aws_access_key_id')    conn = s3connection(aws_keyid, aws_seckey)  except (ioerror, nosectionerror, nooptionerror):         conn = s3connection()  # try env if /etc/boto.cfg missing  except:   raise 

or along lines. key read config instead of assuming environment.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -