Output of `aws configure sso` is broken when piping through `tee`
- Dominant language
- Python
- Stars
- 17.3k
- Forks
- 4.6k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 13
Description
Confirm by changing [ ] to [x] below to ensure that it's a bug:
- [x] I've gone through the [User Guide](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html) and the [API reference](https://docs.aws.amazon.com/cli/latest/reference/)
- [x] I've searched for [previous similar issues](https://github.com/aws/aws-cli/issues) and didn't find any solution
**Describe the bug**
When piping the `aws configure sso` command with `tee` the output is broken, this happens since version `2.4.19` when the `prompt-toolkit` [was upgraded](https://github.com/aws/aws-cli/blob/v2/CHANGELOG.rst#L196).
**SDK version number**
```bash
$ aws --version
aws-cli/2.4.18 Python/3.9.12 Darwin/21.4.0 source/x86_64 prompt/off
```
**Platform/OS/Hardware/Device**
```
###
####
###
####### ####### Distro: OS X 12.3
###################### Kernel: Darwin
##################### Shell: /usr/local/bin/zsh
#################### Terminal: xterm-256color iTerm.app
#################### CPU: Intel Core i7-1068NG7 CPU @ 2.30GHz
##################### Memory: 32 GB
######################
####################
################
#### #####
```
**To Reproduce (observed behavior)**
```bash
$ aws configure sso | tee a.txt
SSO start URL [https://XXXXX.awsapps.com/start]:
| <-- cursor is now here!
```
**Expected behavior**
```bash
$ aws configure sso | tee a.txt
SSO start URL [https://XXXXX.awsapps.com/start]: | <-- cursor should be here
```
**Logs/output**
```bash
$ aws configure sso --debug | tee a.txt
2022-03-31 22:37:26,230 - MainThread - awscli.clidriver - DEBUG - CLI version: aws-cli/2.5.1 Python/3.9.12 Darwin/21.4.0 source/x86_64
2022-03-31 22:37:26,230 - MainThread - awscli.clidriver - DEBUG - Arguments entered to CLI: ['configure', 'sso', '--debug']
2022-03-31 22:37:26,313 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler
2022-03-31 22:37:26,313 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler
2022-03-31 22:37:26,313 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler >
2022-03-31 22:37:26,313 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler
2022-03-31 22:37:26,313 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler
2022-03-31 22:37:26,313 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler
2022-03-31 22:37:26,313 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler
2022-03-31 22:37:26,313 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler >
2022-03-31 22:37:26,313 - MainThread - botocore.hooks - DEBUG - Event building-command-table.main: calling handler
2022-03-31 22:37:26,314 - MainThread - botocore.loaders - DEBUG - Loading JSON file: /usr/local/Cellar/awscli/2.5.1/libexec/lib/python3.9/site-packages/awscli/data/cli.json
2022-03-31 22:37:26,316 - MainThread - botocore.hooks - DEBUG - Event top-level-args-parsed: calling handler
2022-03-31 22:37:26,316 - MainThread - botocore.hooks - DEBUG - Event top-level-args-parsed: calling handler
2022-03-31 22:37:26,316 - MainThread - botocore.hooks - DEBUG - Event top-level-args-parsed: calling handler
2022-03-31 22:37:26,316 - MainThread - botocore.hooks - DEBUG - Event top-level-args-parsed: calling handler
2022-03-31 22:37:26,316 - MainThread - botocore.hooks - DEBUG - Event top-level-args-parsed: calling handler
2022-03-31 22:37:26,316 - MainThread - botocore.hooks - DEBUG - Event top-level-args-parsed: calling handler
2022-03-31 22:37:26,317 - MainThread - awscli.clidriver - DEBUG - CLI version: aws-cli/2.5.1 Python/3.9.12 Darwin/21.4.0 source/x86_64 prompt/off
2022-03-31 22:37:26,317 - MainThread - awscli.clidriver - DEBUG - Arguments entered to CLI: ['configure', 'sso', '--debug']
2022-03-31 22:37:26,317 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler
2022-03-31 22:37:26,317 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler
2022-03-31 22:37:26,317 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler
2022-03-31 22:37:26,317 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler
2022-03-31 22:37:26,317 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler
2022-03-31 22:37:26,323 - MainThread - botocore.utils - DEBUG - IMDS ENDPOINT: http://169.254.169.254/
2022-03-31 22:37:26,336 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler
2022-03-31 22:37:26,336 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler
2022-03-31 22:37:26,337 - MainThread - botocore.hooks - DEBUG - Event building-command-table.configure: calling handler
2022-03-31 22:37:26,337 - MainThread - botocore.hooks - DEBUG - Event building-command-table.configure: calling handler
2022-03-31 22:37:26,337 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.custom.configure.anonymous: calling handler
2022-03-31 22:37:26,337 - MainThread - botocore.hooks - DEBUG - Event building-command-table.configure_sso: calling handler
2022-03-31 22:37:26,338 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.custom.sso.no-browser: calling handler
2022-03-31 22:37:26,338 - MainThread - botocore.hooks - DEBUG - Event process-cli-arg.custom.sso: calling handler
SSO start URL [https://XXXXX.awsapps.com/start]:
| <-- cursor
```
**Additional context**
I use this method in order to catch the profile name generated so I can automatically assign it to AWS_PROFILE env var and all AWS commands will now just work with the role, account and region I just connected to.
This is my nice function for it:
```bash
aws-login() {
unset AWS_PROFILE
local file_name="/tmp/$$"
aws configure sso 2>&1 | tee "$file_name"
export AWS_PROFILE="$(grep "ls \-\-profile" "$file_name" | cut -d" " -f5)"
\rm "$file_name"
}
```
Contributor guide
Assessment
This issue has not been assessed yet.