This should work for you... Needed to setup a few systems with automated cron git pull scripts, which would then execute crontab/anacron run-parts bash scripts which called upon ec2 java tools. Normally in an amz-linux-ami (their RH clone) the creating of env vars goes as follows:
(going to stick to relevant files)
Do shell login --> source /etc/profile
which will loop through /etc/profile.d and source *.{users shell extension}
in this case aws-apitools-common.sh
$cat aws-apitools-common.sh
export AWS_PATH=/opt/aws
export PATH=$PATH:$AWS_PATH/bin
#Prefer JDK if present (i pulled the condition to de-clutter this info)
export JAVA_HOME=/usr/lib/jvm/java
export JAVA_HOME=/usr/lib/jvm/jre
Here is the relevant line:
for aws_product in $(find /opt/aws/apitools /opt/aws/amitools -maxdepth 1 -type l 2>/dev/null); do
[ -e $aws_product/environment.sh ] && source $aws_product/environment.sh; done
So the script aws-apitools-common.sh
searches for apitools and amitools, then sources those tools $aws_product/environment.sh
. ex: source /opt/aws/apitools/ec2/environment.sh
Now this is probably what you are looking for (/opt/aws/apitools/ec2/environment.sh):
$cat environment.sh
# Set EC2_HOME. Called from /etc/profile.d/aws-product-common
[ -z "$EC2_HOME" ] && EC2_HOME="/opt/aws/apitools/ec2"
export EC2_HOME
In short the environmental vars you want set/export in your crontab script, and or your anacron run-parted scripts would be (personally i load in key.conf files which are generated from a git repo, and having a git pull fire off every hour, so keys and the env cat be updated just like the scripts themselves. Then the job script sources the conf file):
AWS_ACCESS_KEY="blah-blah-dingle-smith"
AWS_SECRET_KEY="yankee-doodle-shit-no-stank"
JAVA_HOME="/usr/lib/jvm/java"
EC2_HOME="/opt/aws/apitools/ec2"
EC2_URL="https://us-west-2.ec2.amazonaws.com/"
PATH="$PATH:/opt/aws/bin" # is dir contains a symlinks of tool binaries
Cheers!