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,480 points

edited Aug 8, 2018 by Priyaj 1,796 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 6, 2018 by sunshine
• 1,260 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 in AWS by MD
• 53,620 points
96 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 in AWS by MD
• 53,620 points
65 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,260 points
75 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
• 57,640 points
2,870 views
0 votes
1 answer

How to Enable CORS for an AWS API Gateway Resource

Since you're using Lambda Proxy integration for ...READ MORE

answered Jul 10, 2018 in AWS by Hammer
• 360 points
2,203 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer