|
1
|
import { InlineIcon, getOsShortcut, Kbd } from "docs-ui" |
|
2
|
import { EllipsisHorizontal } from "@medusajs/icons" |
|
3
|
|
|
4
|
export const metadata = { |
|
5
|
title: `Manage Environment Variables`, |
|
6
|
} |
|
7
|
|
|
8
|
# {metadata.title} |
|
9
|
|
|
10
|
In this guide, you'll learn how to manage environment variables of long-lived and preview environments in Cloud. |
|
11
|
|
|
12
|
Environment variables are key-value pairs of sensitive information, such as API keys and credentials. Instead of hardcoding these variables in your codebase, you should store them as environment variables. |
|
13
|
|
|
14
|
You can manage an environment's variables in its **Environment variables** settings. You can manage environment variables for the environment's Medusa backend and storefront (if applicable). |
|
15
|
|
|
16
|
## Restricted Environment Variable Names |
|
17
|
|
|
18
|
The following environment variable names are reserved by Cloud and you can't use them in your environment: |
|
19
|
|
|
20
|
- `NODE_ENV` |
|
21
|
- `EXECUTION_CONTEXT` |
|
22
|
- `DATABASE_URL` |
|
23
|
- `REDIS_URL` |
|
24
|
- `MEDUSA_WORKER_MODE` |
|
25
|
- `PORT` |
|
26
|
- `K_SERVICE` |
|
27
|
- `K_CONFIGURATION` |
|
28
|
- `K_REVISION` |
|
29
|
- `K_CONTAINER_NAME` |
|
30
|
- `K_INTERNAL_POD_NAME` |
|
31
|
- `K_INTERNAL_POD_NAMESPACE` |
|
32
|
- `K_LOCAL_ADDR` |
|
33
|
- `K_PROTOCOL` |
|
34
|
- `SESSION_STORE` |
|
35
|
- `DYNAMO_DB_SESSIONS_TABLE` |
|
36
|
- `DYNAMO_DB_SESSIONS_HASH_KEY` |
|
37
|
- `DYNAMO_DB_SESSIONS_PREFIX` |
|
38
|
- `AWS_ACCESS_KEY_ID` |
|
39
|
- `AWS_SECRET_ACCESS_KEY` |
|
40
|
- `AWS_REGION` |
|
41
|
- `MEDUSA_CLOUD_API_KEY` |
|
42
|
- `MEDUSA_CLOUD_ENVIRONMENT_HANDLE` |
|
43
|
- `MEDUSA_CLOUD_ENVIRONMENT_TYPE` |
|
44
|
- `MEDUSA_CLOUD_ENVIRONMENT_NAME` |
|
45
|
- `MEDUSA_CLOUD_PROJECT_HANDLE` |
|
46
|
- `MEDUSA_CLOUD_EMAILS_ENDPOINT` |
|
47
|
- `MEDUSA_CLOUD_SEARCH_ENDPOINT` |
|
48
|
|
|
49
|
--- |
|
50
|
|
|
51
|
## System Environment Variables |
|
52
|
|
|
53
|
Cloud automatically provides the following system environment variables in all environments at both runtime and build time: |
|
54
|
|
|
55
|
- `MEDUSA_CLOUD_ENVIRONMENT_HANDLE`: The unique handle/identifier for the environment |
|
56
|
- `MEDUSA_CLOUD_ENVIRONMENT_TYPE`: The type of environment (`production`, `preview-instance`, or `long-lived`) |
|
57
|
- `MEDUSA_CLOUD_ENVIRONMENT_NAME`: The display name of the environment. For example, "Production" or "Staging". |
|
58
|
- `MEDUSA_CLOUD_PROJECT_HANDLE`: The unique handle/identifier for the project |
|
59
|
|
|
60
|
These variables are automatically set by Cloud and don't need to be configured manually. You can use them in your application code to access information about the current environment context. |
|
61
|
|
|
62
|
--- |
|
63
|
|
|
64
|
## Search and Filter Environment Variables |
|
65
|
|
|
66
|
You can search and filter the environment variables using the toolbar above the environment variables table: |
|
67
|
|
|
68
|
- **Search**: Enter a key name or value in the search field to filter the list in real time. |
|
69
|
- **Build / Runtime toggles**: Show only variables available at build time, only those available at runtime, or both at once. |
|
70
|
- **System Variables toggle**: Show or hide system-managed variables. System variables are hidden by default. |
|
71
|
|
|
72
|
--- |
|
73
|
|
|
74
|
## System Environment Variables Visibility |
|
75
|
|
|
76
|
In addition to the [system environment variables](#system-environment-variables) documented above, the **Backend** view displays all system-provided variables alongside your user-defined ones when the **System Variables** toggle is enabled. These are variables that Medusa adds to your environment, such as database URL, Redis URL, and other relevant variables. |
|
77
|
|
|
78
|
System variables are visually distinguished from user-defined variables with a subtle background and muted text. Because Medusa manages those: |
|
79
|
|
|
80
|
- The edit and delete actions are not available for system variables. |
|
81
|
- Secret system variables do not show the reveal (eye) icon. |
|
82
|
|
|
83
|
System variables are useful to understand what variables Medusa sets for you so that you don't add them as well. |
|
84
|
|
|
85
|
--- |
|
86
|
|
|
87
|
## Add Environment Variables on Cloud |
|
88
|
|
|
89
|
To add environment variables to an environment: |
|
90
|
|
|
91
|
<Note title="Tip"> |
|
92
|
|
|
93
|
You can also navigate to an environment's variables from the [command palette](../../command-palette/page.mdx). Press <Kbd>{getOsShortcut()}</Kbd> + <Kbd>K</Kbd>, select **Edit Variables**, then choose a project. |
|
94
|
|
|
95
|
</Note> |
|
96
|
|
|
97
|
1. In the [environment's dashboard](../long-lived/page.mdx#open-environment-dashboard), click **Environment variables** in the sidebar. |
|
98
|
2. If you deployed both the Medusa backend and storefront in the environment, use the **Backend** or **Storefront** tabs to switch between managing the backend and storefront environment variables. |
|
99
|
3. In the "Add new environment variables" section, you can add environment variables either for the backend or storefront. There are different ways you can add environment variables: |
|
100
|
- **Manually**: |
|
101
|
- Enter the key and value of the environment variable in the respective fields. |
|
102
|
- Use the **Sensitive** toggle to mark variables containing secrets that should be masked in the interface. |
|
103
|
- Use the **Build** toggle to make the variable available during build time. |
|
104
|
- Use the **Runtime** toggle to make the variable available during runtime (enabled by default). |
|
105
|
- Click the "Add another" button to add another variable. |
|
106
|
- **Paste `.env` format**: |
|
107
|
- If you copied environment variables in a `.env` file format, you can paste them directly into the "Key" field. The environment variables will be pre-filled for you. |
|
108
|
- **Import `.env` file**: |
|
109
|
- If you have a `.env` file that defines your environment variables, click the "Import .env" button to upload the file. The environment variables will be automatically extracted and added to the list. |
|
110
|
4. Once you're done, click the "Save" button to save the environment variables. |
|
111
|
|
|
112
|
<Note title="Important"> |
|
113
|
|
|
114
|
After adding the environment variables, you must [redeploy the environment](../long-lived/page.mdx#redeploy-environment) for the changes to take effect. |
|
115
|
|
|
116
|
</Note> |
|
117
|
|
|
118
|
--- |
|
119
|
|
|
120
|
## Edit Environment Variables on Cloud |
|
121
|
|
|
122
|
To edit an environment variable: |
|
123
|
|
|
124
|
<Note title="Tip"> |
|
125
|
|
|
126
|
You can also navigate to an environment's variables from the [command palette](../../command-palette/page.mdx). Press <Kbd>{getOsShortcut()}</Kbd> + <Kbd>K</Kbd>, select **Edit Variables**, then choose a project. |
|
127
|
|
|
128
|
</Note> |
|
129
|
|
|
130
|
1. In the [environment's dashboard](../long-lived/page.mdx#open-environment-dashboard), click **Environment variables** in the sidebar. |
|
131
|
2. If you deployed both the Medusa backend and storefront in the environment, use the **Backend** or **Storefront** tabs to switch between managing the backend and storefront environment variables. |
|
132
|
3. In the "Environment variables" section, find the variable you want to edit. |
|
133
|
4. Click the <InlineIcon Icon={EllipsisHorizontal} alt="three-dots" /> icon at the variable's right side. |
|
134
|
5. Choose "Edit" from the dropdown menu. |
|
135
|
|
|
136
|
6. In the side window that opens, you can edit the variable's key, value, and configure its settings: |
|
137
|
- **Sensitive**: Whether the variable contains secrets that should be masked in the interface |
|
138
|
- **Build**: Whether the variable is available during build time |
|
139
|
- **Runtime**: Whether the variable is available during runtime |
|
140
|
7. Once you're done, click the "Save" button. |
|
141
|
|
|
142
|
<Note title="Important"> |
|
143
|
|
|
144
|
After editing the environment variable, you must [redeploy the environment](../long-lived/page.mdx#redeploy-environment) for the changes to take effect. |
|
145
|
|
|
146
|
</Note> |
|
147
|
|
|
148
|
--- |
|
149
|
|
|
150
|
## Delete Environment Variables on Cloud |
|
151
|
|
|
152
|
To delete an environment variable: |
|
153
|
|
|
154
|
<Note title="Tip"> |
|
155
|
|
|
156
|
You can also navigate to an environment's variables from the [command palette](../../command-palette/page.mdx). Press <Kbd>{getOsShortcut()}</Kbd> + <Kbd>K</Kbd>, select **Edit Variables**, then choose a project. |
|
157
|
|
|
158
|
</Note> |
|
159
|
|
|
160
|
1. In the [environment's dashboard](../long-lived/page.mdx#open-environment-dashboard), click **Environment variables** in the sidebar. |
|
161
|
2. If you deployed both the Medusa backend and storefront in the environment, use the **Backend** or **Storefront** tabs to switch between managing the backend and storefront environment variables. |
|
162
|
3. In the "Environment variables" section, find the variable you want to delete. |
|
163
|
4. Click the <InlineIcon Icon={EllipsisHorizontal} alt="three-dots" /> icon at the variable's right side. |
|
164
|
5. Choose "Delete" from the dropdown menu. |
|
165
|
|
|
166
|
<Note title="Important"> |
|
167
|
|
|
168
|
After deleting the environment variable, you must [redeploy the environment](../long-lived/page.mdx#redeploy-environment) for the changes to take effect. |
|
169
|
|
|
170
|
</Note> |
|
171
|
|
|
172
|
--- |
|
173
|
|
|
174
|
## Export Environment Variables on Cloud |
|
175
|
|
|
176
|
You can export an environment's variables as a `.env` file. This is useful for debugging issues that require you to have the same environment variables. |
|
177
|
|
|
178
|
To export an environment's variables: |
|
179
|
|
|
180
|
<Note title="Tip"> |
|
181
|
|
|
182
|
You can also navigate to an environment's variables from the [command palette](../../command-palette/page.mdx). Press <Kbd>{getOsShortcut()}</Kbd> + <Kbd>K</Kbd>, select **Edit Variables**, then choose a project. |
|
183
|
|
|
184
|
</Note> |
|
185
|
|
|
186
|
1. In the [environment's dashboard](../long-lived/page.mdx#open-environment-dashboard), click **Environment variables** in the sidebar. |
|
187
|
2. If you deployed both the Medusa backend and storefront in the environment, use the **Backend** or **Storefront** tabs to switch between managing the backend and storefront environment variables. |
|
188
|
3. In the "Environment variables" section, click on the "Export .env" button at the top right of the section. |
|
189
|
|
|
190
|
A file download will start with the name `env.txt`, which contains the environment variables in `.env` format. |
|
191
|
|
|
192
|
You can rename the file to `.env` and use it in your local development. |
|
193
|
|