How can I get the aws profile id from the aws configure sso command

26 Views Asked by At

As part of a bash script to automate connecting to our postgres instance I need to configure the aws cli tool and set the AWS_PROFILE variable. The command outputs this in the final line of its output.

The problem is that aws configure sso is interactive so I can't just dump the output in a variable. So I have done the following:

AWS_OUTPUT=$(aws configure sso | tee /dev/tty)
export AWS_PROFILE=$(tail -1 <<< "$AWS_OUTPUT" | cut -d' ' -f5)

This works, but its hard to use because every time I press any key while aws configure sso is running a carriage return is also inserted and the output is very confusing (though barely usable).

Is there a better way to get the profile id? Or a way to prevent the carriage return issue?

0

There are 0 best solutions below