Environment variables can be set to your Micro through the Deta cli's update command. These variables are encrypted at rest.
You need to create a file where you specify your environment variables with their values.
We stronlgy recommend creating a file called
.env so that this file is skipped by the Deta cli and not deployed with your Micro's code. Also, please do not share/commit your env file publicly.
You can use the following command to update your enviornment variables:
The environment variables must be defined in the following format:
You should not change the value of the environment variables through your Micro's code, as the change will not persist in following invocations of your Micro.
Suppose you want to make an environment variable
SECRET_TOKEN with a value of
abcdefgh accessible to your Micro's code.
- Create a
.envfile with the following content:
- Update the Micro's environment variables with the
Deta pre-sets some environment variables in your Micro's environment which are used by our runtime.
These pre-set variables are specific to your Micro and should not be shared publicly (unless we mention otherwise). These variables can not be updated from the cli.
The following pre-set environment variables could be useful for you:
DETA_PATH stores a unique identifier for your Micro. This value is also used as the sub-domain under which your Micro is avaiable through
http. For example, if your
DETA_PATH variable contained a value of
sdfgh then your Micro is accessible at https://sdfgh.deta.dev.
This value does not store the self assigned sub-domain value at the moment.
DETA_RUNTIME indicates if your code is running on a Micro, with a string value
In some cases, you might need to run some code exclusively in local development and not in a Micro. For example, if you're running a FastAPI project on your Micro, and you've got an endpoint that dumps debug information like so:
If you want this endpoint to be only available locally, you can check the environment variable to selectively execute code:
Each micro has its own project key and this should not be shared publicly.
While using our SDKs(the latest versions) within a Deta Micro, you can omit specifying the project key when instantiating a service instance.