I'm trying to upload files to an S3 bucket and I'm using
However, if I access S3_BUCKET
in code when running locally, the value returned is None:
S3_BUCKET = os.environ.get('S3_BUCKET')
print("value of S3_BUCKET: " S3_BUCKET)
This prints None
.
Does anyone know why this doesn't work? The frontend of my application is in React, if that matters, but all of the bucket upload code is done in python.
CodePudding user response:
heroku config:set
sets variables on Heroku. Like their name suggests, environment variables are specific to a particular environment. Settings set this way have no impact on your local machine.
There are several ways to set environment variables locally. One common method involves putting them into an untracked .env
file. Many tools, including heroku local
, read that file and add variables found there to the environment when running locally.
Heroku recommends this, though you will have to make sure whatever tooling you use picks up those variables. Aside from heroku local
, Visual Studio Code understands .env
files for Python projects. So does Pipenv. There are also standalone tools for this like direnv.