amazon web services - How to override the env variables and use the AWS credential file instead in AWS CLI? -


when using aws cli, there way can specify use credential file instead of values stored in env variables?

$ aws ec2 describe-instances --profile saml

saml profile name inside credentials file stored in ~/.aws/credentials. want aws cli use credential file default , not use ones stored in env variable. how can this?

unfortunately, can't specify priority credential file on environment variables.

http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-environment

environment variables override configuration , credential files , can useful scripting or temporarily setting named profile default.

building mentioned in answer, write wrapper script would:

  • overwrite environment variables export command (which think temporary within scope of script only)
  • pass through command aws cli
  • once completed, wrapper script terminate , environment variables should go way (i think)

i tested out below (very basic) bash script. have environment variable called $region. consider below shell script called "script.sh".

#!/bin/bash export region="" echo "region = "$region 

before calling script, 'echo $region' prove exist:

ubuntu@ip-172-31-24-61:~$ echo $region us-east-1 

i call script, nulls out variable , echo's showing it's empty.

ubuntu@ip-172-31-24-61:~$ ./script.sh region = 

once script terminates, 'echo $region' command line , environment variable fine.

ubuntu@ip-172-31-24-61:~$ echo $region us-east-1 

if apply use case, write wrapper script nulls out environment variable (by export aws_access_key_id=""), passes of command line options through aws cli. when cli executes, not see environment variables because have been nulled out in scope of execution.

the 1 thing don't know how have bash script take of unknown number of command line arguments , pass them through command. don't envision it's difficult, don't know how it.

but, i'm sure if create question, can help!

the alternative is, delete environment variables if won't ever use them.

edit 2 i've found out how make simple wrapper script should solve problem. before implement this, suggest looking @ following links better idea of how works , other methods may out there accomplishing this. example, can use $@ , maybe $* , may more accepted way.

#!/bin/bash  params="" export aws_access_key_id="" export aws_secret_access_key=""  arg;         params="$params $arg" done  aws $params 

the 2 'export' links null out environment variables. again, environment variables nulled out life of wrapper script, because it's being done within scope of script , not globally.

then, loop loops through of command line arguments used run script, appends them string variable , calls 'aws' string holding of command line arguments.

http://tldp.org/ldp/abs/html/wrapper.html
bash: convert command line arguments array
https://linuxconfig.org/bash-script-how-to-check-number-of-supplied-command-line-arguments
check number of arguments passed bash script


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -