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年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン