Export not working
Hi,
I have installed awstools a few days ago and I think it is a really nice solution. The problem is, the created keys are not exported to my shell. Using zsh and not sure why this is happening.
Hope you can help.
Cheers, Lars
Hi @kinderlars , yes, zsh is tricky. The idea is that awstools assume prints a shell script that must be sourced into your current shell session. It is difficult to debug remotely. To reproduce I'd need:
- In what file did you define
aws_assume()function? - What
zshversion do you use? - Do you use any additional plugins with
zsh?
P.S. You might consider to use awscredx if you are mostly interested in the role assumption. That project has focus on role assumptions.
Hi @sam701,
thanks for the quick response.
I am using zsh 5.8 (x86_64-apple-darwin19.6.0)
I defined the assume_role() function in .bash_profiles and added source /Users/lars/.bash_profile to my .zshenv file
Cheers, Lars
You do not actually need a separate .bash_profile, you can define assume_role directly in .zshenv. Next please check if it's not a typo: you wrote .bash_profiles (plural) but source ../.bash_profile (singular).
What's happening when you type assume_role abc abc in your shell?
Was a typo, sorry about that.
Added the aws_assume() to .zshenv now
assume_role zsh: command not found: assume_role
It means .zshenv is not loaded by your shell. I suppose if you explicitly call source ~/.zshenv it will work. You should make sure you define aws_assume in a file that is sourced by your shell. Otherwise the shell is not aware of the function.
Thanks a lot for the help. :) Sadly even when sourcing, the function still does not get detected. Any other idea why this could happen?
@sam701 , got the function assume_role to work.
Somehow it was not able to detect my config.toml so.
aws_assume ACCOUNT ROLE 2021/04/30 11:05:45 ERROR open /Users/lars/.config/awstools/awstools.toml: no such file or directory
Had to rename the file from config.toml to awstools.toml
A new problem, now I am not able to run awstools assume anymoe :D
awstools assume ACCOUNT ROLE 2021/04/30 11:13:49 ERROR open /Users/lars/.config/awstools/config.toml: no such file or directory
Could you paste your assume_role shell function? And also the output of awstools assume none none?
Hi @sam701,
I removed the assume_role from my zshenv and now only using the helper script function.
function aws_assume() { config_file="${config_dir}/awstools.toml" creds_file=$(mktemp) awstools --config ${config_file} assume --export ${creds_file} $@; source ${creds_file}; rm ${creds_file} }
In addition awstools now works as intended as well.
awstools assume none none 2021/05/04 15:31:58 No such account: none
Not sure what is different, but the issue can be closed, as it was on my end.
Thanks again for supporting me. :)
@sam701 : Sorry about it, forgot that the export with awstools assume was the original problem.
That is still not working, therefore I re-opened the ticket.
Hmm, I couldn't reproduce this issue. Here is what I did:
cp ~/.config/awstools/config.toml /tmp/tt.toml
cat > /tmp/tt.sh <<EOF
function aws_assume() {
config_file="/tmp/tt.toml"
creds_file=\$(mktemp)
awstools --config \${config_file} assume --export \${creds_file} \$@; source \${creds_file};
cat \${creds_file}
rm \${creds_file}
}
EOF
zsh --version
export SHELL=$(which zsh)
source /tmp/tt.sh
aws_assume my_account my_role
Can you try the same, obfuscate and paste the output?