AWS Elastic Beanstalk: Running Cron.d script, missing Environment Variables

前端 未结 9 1158
没有蜡笔的小新
没有蜡笔的小新 2021-01-17 10:39

I\'m trying to run a PHP script that is triggered by a cron script (in cron.d). The script is triggered properly but it is missing the Elastic Beanstalk \"Environment Variab

9条回答
  •  时光说笑
    2021-01-17 10:56

    I know this is an old thread but I recently needed to do something similar in a Node.js environment deployed on Elastic Beanstalk; for what I could tell, the file /opt/elasticbeanstalk/support/envvars is not present on Node.js environments. I ended up writing a Python script that loaded the environment variables from /opt/elasticbeanstalk/bin/get-config, and then executing my Node.js script from there.

    The code I ended up using was:

    #!/usr/bin/env python
    
    import os
    import subprocess
    from subprocess import Popen, PIPE, call
    import simplejson as json
    
    envData = json.loads(Popen(['/opt/elasticbeanstalk/bin/get-config', 'environment'], stdout = PIPE).communicate()[0])
    
    for k, v in envData.iteritems():
        os.environ[k] = v
    
    call(["babel-node", "/var/app/current/.js"])
    

    Hope this helps anyone needing to do the same.

    For the complete configuration I deployed, you can refer to my original post How to set environment variables in Amazon Elastic Beanstalk when running a cron job (Node.js)

提交回复
热议问题