Test AWS credentials using AWS CLI
Testing for AWS credentials is a straightforward operation.
Using get-caller-identity
There is a single API call that will always work regardless of permissions: GetCallerIdentity
1aws sts get-caller-identity
Output:
1{
2 "UserId": "AIDA...",
3 "Account": "123456789012",
4 "Arn": "arn:aws:iam::123456789012:user/thomas"
5}
The Arn
value depends on the type of credentials, but mostly includes the human-friendly name.
In addition, checking the status is reliable: 0
for success, 255
for failure.