How to add EB Environ prop references for cron.d on AWS EB Amazon Linux 2?

0

I updated AWS platform from "Python 3.6 running on 64bit Amazon Linux" to "Python 3.7 running on 64bit Amazon Linux 2" and I'm not able to execute crons because I don't know how to add reference for Django environment settings (stored to EB Environment properties) there. Could you help me?

On the old platform everything works fine with this ".ebextensions/cron.config" setup:

files:  
"/etc/cron.d/mycron":  
    mode: "000644"  
    owner: root  
    group: root  
    content: |  
        3 ** ** ** ** root /usr/local/bin/script.sh > /home/ec2-user/script.log 2>&1  

"/usr/local/bin/script.sh":  
    mode: "000755"  
    owner: root  
    group: root  
    content: |  
        #!/bin/bash  

        date > /tmp/date  
        # actual script content  
        source /opt/python/run/venv/bin/activate  
		source /opt/python/current/env  
		cd /opt/python/current/app/  
		python manage.py send_notification  
        exit 0  

I know that I have to make changes on Linux 2 platform and I have to run activate -script from different location and this is what I have now:

files:  
"/etc/cron.d/mycron":  
    mode: "000644"  
    owner: root  
    group: root  
    content: |  
        3 ** ** ** ** root /usr/local/bin/script.sh > /home/ec2-user/script.log 2>&1  

"/usr/local/bin/script.sh":  
    mode: "000755"  
    owner: root  
    group: root  
    content: |  
        #!/bin/bash  

        date > /tmp/date  
        # actual script content  
        source /var/app/venv/*/bin/activate  
        cd /var/app/current/  
        python manage.py send_notification  
        exit 0  

I have also noticed that everything works fine when I try to do the same from .platform/hooks/predeploy and executing python from /var/app/staging, but that path is not available later on. The problem is that os.Environment - variables were not loaded from the EB configuration and I got KeyError from os.Environment key - reference.

Edited by: NanNull on Nov 10, 2020 9:36 PM

Edited by: NanNull on Nov 10, 2020 9:37 PM

Edited by: NanNull on Nov 10, 2020 9:45 PM

Edited by: NanNull on Nov 10, 2020 9:47 PM

Edited by: NanNull on Nov 10, 2020 9:54 PM

N3_team
已提問 3 年前檢視次數 237 次
1 個回答
0

If someone else is looking for resolution, I already resolved the problem with help of this document: https://aws.amazon.com/premiumsupport/knowledge-center/elastic-beanstalk-env-variables-linux2/

N3_team
已回答 3 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南