Last active
July 18, 2019 14:26
-
-
Save medwig/09ad7dc08e50237e69696672e728c05c to your computer and use it in GitHub Desktop.
Bash alias run sls with --aws-profile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set default aws-profile | |
AWS_PROFILE=myprofile | |
# Run sls with an aws-profile | |
sls_with_aws_profile() { | |
if [ -z ${AWS_PROFILE+x} ]; | |
then printf "\e[1;31mAWS_PROFILE is not set\e[0m\n$ export AWS_PROFILE=profile_name\n" \ | |
&& return; | |
fi | |
export AWS_SDK_LOAD_CONFIG=true; | |
(>&2 printf "profile:\e[32m $AWS_PROFILE\e[0m\n\n";); | |
\sls --aws-profile $AWS_PROFILE "$@"; | |
} | |
alias sls="sls_with_aws_profile" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Easily deploy to multiple AWS accounts with serverless framework. Set the AWS_PROFILE variable to the desired account name in
~/.aws/config
(or~/.aws/credentials
) by running:$ export AWS_PROFILE=target_profile
A default profile can be set in .bashrc if desired (line 2).
Commands can then be run as usual in serverless:
$ sls info
and it will be expanded to
$ sls --aws-profile info
The profile will be printed to stderr before each execution to make it clear what profile the account is running on. Printing to stderr means it will not interfere with piped output, for example to
jq
:$ sls invoke -f fooFunc | jq
This call will print the profile, and the stdout of the call will be passes to jq, everything will work as expected.