- Newest
- Most votes
- Most comments
Hello, we have provided a general way for you to access environment variables. In your case, you might need to do something like:
build:
commands:
- ENV_NAME=$ENV_NAME
- npm run build
To use environment variables during a build in AWS Amplify, follow these steps.
-
Go to the AWS Amplify Console in the AWS Management Console and select the app that you want to configure.
-
Inside your app's dashboard, click on "Backend environments" on the left menu, and then choose "Edit" for the environment you want to work with (e.g., staging or production).
-
Configure Environment Variables: In the environment settings, you'll find an option to add environment variables. You can add key-value pairs representing your environment-specific variables.
For example:
MY_API_URL=https://api.example.com DEBUG_MODE=true
These environment variables will be accessible during the build process.
-
In your build configuration file (e.g.,
amplify.yml
orbuildspec.yml
), you can access the environment variables using the syntax for the respective build platform.-
For AWS Amplify Console's built-in build platform, you can access environment variables using the following syntax:
version: 1 frontend: phases: build: commands: - echo "My API URL: $MY_API_URL"
-
If you're using AWS Amplify with a custom build environment, you might use different methods to access the environment variables based on the specific build tools and platform you are using.
-
-
When you trigger a new build or deploy your application, AWS Amplify will automatically use the environment variables you defined during the build process. This allows your application to adapt to different environments based on the specified variables.
Relevant content
- asked a year ago
- asked 2 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 3 years ago