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

edited Aug 8, 2018 by Priyaj 75 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,160 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

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,150 points
24 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
• 56,160 points
929 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
431 views
0 votes
1 answer
0 votes
1 answer

Login to AWS from AWS Tools for Powershell

If your IAM user account doesn't already ...READ MORE

answered Jul 18, 2018 in AWS by Priyaj
• 56,160 points
45 views
0 votes
2 answers

How to configure Amazon EC2 command line interface?

You can use this command to create ...READ MORE

answered Feb 23 in AWS by Shashank
• 1,350 points
62 views
0 votes
1 answer