Home > Clouds > AWS > AWS FAQs > How can I export AWS environment variables to the shell?

How can I export AWS environment variables to the shell?

Background Information

In some instances you may want to export all of the AWS environment variables, credentials, and key files to a running instance so you don't have to set them up manually.



The following RightScript will do this for you by creating a script in /root that will export all of the AWS environment variables as well as a key.pem and a cert.pem file.  To set the environment variables simply run this RightScript (or install it as a boot script).  When you ssh into the instance you will find setenv, key.pem, and cert.pem in /root.  You can then use this from the command line to set the environment variables in your shell by typing:


source /root/setenv

You can cut and paste the script below into a new RightScript and then install it on the template as an operational or boot script.


echo 'export AWS_ACCESS_KEY_ID='$AWS_ACCESS_KEY_ID > /root/setenv

echo 'export AWS_SECRET_ACCESS_KEY='$AWS_SECRET_ACCESS_KEY >> /root/setenv

echo 'export AWS_ACCOUNT_NUMBER='$AWS_ACCOUNT_NUMBER >> /root/setenv

echo 'export EC2_AMI_ID='$EC2_AMI_ID >> /root/setenv

echo 'export EC2_AKI_ID='$EC2_AKI_ID >> /root/setenv

echo 'export EC2_ARI_ID='$EC2_ARI_ID >> /root/setenv

echo 'export EC2_AMI_MANIFEST_PATH='$EC2_AMI_MANIFEST_PATH >> /root/setenv


echo 'export EC2_HOSTNAME='$EC2_HOSTNAME >> /root/setenv

echo 'export EC2_INSTANCE_ID='$EC2_INSTANCE_ID >> /root/setenv

echo 'export EC2_INSTANCE_TYPE='$EC2_INSTANCE_TYPE >> /root/setenv

echo 'export EC2_LOCAL_HOSTNAME='$EC2_LOCAL_HOSTNAME >> /root/setenv

echo 'export EC2_PUBLIC_HOSTNAME='$EC2_PUBLIC_HOSTNAME >> /root/setenv

echo 'export EC2_PUBLIC_IPV4='$EC2_PUBLIC_IPV4 >> /root/setenv

echo 'export EC2_RESERVATION_ID='$EC2_RESERVATION_ID >> /root/setenv

echo 'export EC2_SECURITY_GROUPS='$EC2_SECURITY_GROUPS >> /root/setenv

echo 'export RS_SERVER='$RS_SERVER >> /root/setenv

echo 'export RS_SKETCHY='$RS_SKETCHY >> /root/setenv

echo 'export RS_TOKEN='$RS_TOKEN >> /root/setenv


chmod 700 /root/setenv

echo "$AWS_X509_CERT" > /root/cert.pem

echo "$AWS_X509_KEY" > /root/key.pem
You must to post a comment.
Last modified
21:25, 16 May 2013



This page has no classifications.



Glossary | 用語용어 Site Map | Site Help Community Corporate Site Get Support Dashboard Login
Doc Feedback Product Feedback Resources MultiCloud Marketplace Forums

Dashboard Status

© 2006-2014 RightScale, Inc. All rights reserved.
RightScale is a registered trademark of RightScale, Inc. All other products and services may be trademarks or servicemarks of their respective owners.