Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Environment Variables on AWS Elastic Beanstalk #162

Closed
DonGuillotine opened this issue Oct 4, 2023 · 5 comments
Closed

Issue with Environment Variables on AWS Elastic Beanstalk #162

DonGuillotine opened this issue Oct 4, 2023 · 5 comments

Comments

@DonGuillotine
Copy link

When deploying a Django application on AWS Elastic Beanstalk, I encountered a problem with python-decouple. It seems unable to fetch environment variables set in the Elastic Beanstalk environment, even though they are available on the instance.

Steps to reproduce:

  1. Set up a Django project using python-decouple to fetch environment variables.
  2. Deploy to AWS Elastic Beanstalk.
  3. Ensure environment variables are set in the Elastic Beanstalk configuration.
  4. Access the Django application.

Expected Result:

  • python-decouple should fetch the environment variables correctly.

Actual Result:

  • python-decouple throws an UndefinedValueError indicating that it can't find the environment variable.

Workaround:

Switching to os.environ.get() works, indicating the issue is with python-decouple and not the environment setup.

Environment:

  • Python version: 3.11
  • python-decouple version: 3.8
  • AWS Elastic Beanstalk Platform Version: Python 3.11 running on 64bit Amazon Linux 2023/4.0.3
@hazemAzzam
Copy link

check this pull request
https://github.com/HBNetwork/python-decouple/pull/165

I have encountred the same issue, and I found that it retrieves the values from the os.environ first before checking the repository file so that when you update your variables it does not updated in the os.environ
so I changed the if statement to check the repository file first

@DonGuillotine
Copy link
Author

check this pull request https://github.com/HBNetwork/python-decouple/pull/165

I have encountred the same issue, and I found that it retrieves the values from the os.environ first before checking the repository file so that when you update your variables it does not updated in the os.environ so I changed the if statement to check the repository file first

Thanks @hazemAzzam, I hope it gets merged.

@almdudler777
Copy link

Does this problem still exist? The Problem of @hazemAzzam was with .env files.

As i understand this Issue; you're not using .env files??
Sorry if that question is obsolete - i'm not familliar with AWS Beanstalk.

The UndefinedValueError is only raised in one spot - after decouple checks the os.environ and then its internal repository (either .env or .ini file). If neither does contain the key you're looking for the error is raised.

It checks the os.environ by using its __contains__ method - ie. by doing if key in os.environ: return os.environ[key].

When you say you worked around this by using os.environ.get(key); which should only differ from os.environ[key] by not raising KeyError if key does not exist.

When you switched to os.environ.get(...) are you by any chance supplying a default (2nd param) aswell?

@henriquebastos
Copy link
Collaborator

The PR was closed, so I am closing this issue too since we can't reproduce it.

@DonGuillotine
Copy link
Author

Apologies for any inconvenience caused, I found out that I activated the wrong virtual Environment.

Once I activated the correct one python-decouple was able to fetch environment variables set in the Elastic Beanstalk environment correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants