I have experimented with many approaches to setting permanent environment variables EC2 instances running Amazon Linux 2, but none of the approaches are persistent across users and across login sessions.
What specific syntax and process will successfully set environment variables so that the values of the variables will be available to all users and during every session?
So far, methods that I have tried include setting values separately in each of the following three files during the USERDATA's launch script for the instance:
/etc/csh.cshrc /etc/environment /etc/profile
I tried each file one at a time and not all three at the same time.
I also tried using Python's
os.environ but that did not work either.
Per @NasirRiley's suggestion, it now works when I create a
setVars.sh file and place it in
/etc/profile.d during the instance's
USERDATA startup sequence:
#!/bin/bash export SOME_VAR_NAME=some-var-value