Empty cli cache file breaks aws cli
- 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 though 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**
I have a profile configured in `~/.aws/config` that auto-assumes a role based on my instance's profile (`credential_source=Ec2InstanceMetadata`). Due to accidentally running out of disk on my machine I ended up having a zero-length JSON file in `~/.aws/cli/cache/`. Once that happened, any aws cli operation I would try was producing a cryptic error with no indication of what went wrong. Only later I discovered that the cryptic message matched the name of the cache file that was broken. Once I removed the defective file, awscli resumed operation as normal.
**SDK version number**
```
$ aws --version
aws-cli/1.16.300 Python/2.7.18 Linux/4.14.186-146.268.amzn2.x86_64 botocore/1.13.36
```
**Platform/OS/Hardware/Device**
```
$ cat /etc/os-release
NAME="Amazon Linux"
VERSION="2"
ID="amzn"
ID_LIKE="centos rhel fedora"
VERSION_ID="2"
PRETTY_NAME="Amazon Linux 2"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
HOME_URL="https://amazonlinux.com/"
```
**To Reproduce (observed behavior)**
To reproduce the reported issue, empty he cache file and try executing any awscli command.
```
$ ls -la ~/.aws/cli/cache/
total 4
drwxrwxr-x 2 ec2-user ec2-user 59 Sep 8 23:27 .
drwxrwxr-x 3 ec2-user ec2-user 19 Sep 8 23:19 ..
-rw------- 1 ec2-user ec2-user 1008 Sep 8 23:19 f1a102925251261c70ff2a2d9afc5e8c8a5fb7d6.json
$ echo -n > ~/.aws/cli/cache/f1a102925251261c70ff2a2d9afc5e8c8a5fb7d6.json
$ AWS_PROFILE=myprofile aws s3 ls
'f1a102925251261c70ff2a2d9afc5e8c8a5fb7d6'
```
**Expected behavior**
I would expect that either
1. the JSON file would get re-generated without error, or
2. the awscli would spit out a descriptive error message that would allow me to address the issue.
**Logs/output**
Not applicable/see above.
Contributor guide
Assessment
This issue has not been assessed yet.