How to test credentials for AWS Command Line Tools

0 votes

Is there a command/subcommand that can be passed to the aws utility that can 

1) verify that the credentials in the ~/.aws/credentials file are valid, and 

2) give some indication which user the credentials belong to? 

I'm looking for something generic that doesn't make any assumptions about the user having permissions to IAM or any specific service. The use case for this is a deploy-time sanity check to make sure that the credentials are good. Ideally there would be some way to check the return value and abort the deploy if there are invalid credentials.

Aug 3, 2018 in AWS by bug_seeker
• 15,510 points

edited Aug 8, 2018 by Priyaj 6,024 views

2 answers to this question.

0 votes

This command would work irrespective of the IAM policies

>aws sts get-caller-identity

The output of this command would be

{
    "Account": "123456789012", 
    "UserId": "AR#####:#####", 
    "Arn": "arn:aws:sts::123456789012:assumed-role/role-name/role-session-name"
}
The credentials can be found easily based on the error codes starting from 0-255
0-success
1-limited S3 commands
255- Command fail,etc

answered Aug 7, 2018 by sunshine
• 1,300 points
0 votes

This command always works regardless of the IAM permission

>aws sts get-caller-identity

you will get the output as
{
    "UserId": "################"
    "Account": "9876543221",
    "Arn": "arn:aws:iam::9876543221:user/content"
}

It uses error codes from 0-255 to specify the type of credentials

like 0 for success, 1 for S3 commands and 255 for command fail

answered Aug 8, 2018 by anonymous

Related Questions In AWS

+1 vote
1 answer

How to find all instance Ids In AWS from command line?

Hi@akhtar, You can find one keyword --query in ...READ MORE

answered Jun 2, 2020 in AWS by MD
• 95,460 points
5,572 views
–1 vote
1 answer

How to find AWS instance Ids in yaml format from command line?

Hi@akhtar, By default AWS gives output in json ...READ MORE

answered Jun 2, 2020 in AWS by MD
• 95,460 points
792 views
0 votes
1 answer

How to check the state of the snapshot from the command line in AWS?

Hi@akhtar, You can check the state of the snapshot ...READ MORE

answered Oct 20, 2020 in AWS by MD
• 95,460 points
1,304 views
0 votes
1 answer

How to copy a snapshot in AWS from the command line?

Hi@akhtar, The following copy-snapshot example command copies the specified snapshot ...READ MORE

answered Oct 20, 2020 in AWS by MD
• 95,460 points
1,104 views
0 votes
1 answer

How to test code written against AWS API

The actual uploading and the tests that ...READ MORE

answered May 17, 2018 in AWS by Flying geek
• 3,280 points
661 views
+1 vote
3 answers

How to get ARN for s3 Bucket using aws cli .

An ARN is a non-opaque, constructible identifier, ...READ MORE

answered Aug 16, 2018 in AWS by Priyaj
• 58,020 points
5,629 views
0 votes
1 answer
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP