Although I work for AWS, I don't work for the product teams for the technologies mentioned in this post. However, I make every effort to ensure the accuracy of the contents; my position is not official.
If you have many AWS accounts, sometimes you may forget the account id and username for a pair of access key IDs and secret access keys. Fortunately, you can recover it. After all, you can authenticate with AWS with just access key ID and secret access key. So, there must be a way to link them to your AWS Accounts.
The following is the C# code that can recover the account id and username,
-
- using Amazon.Runtime;
- using Amazon.SecurityToken;
- using Amazon.SecurityToken.Model;
- using System;
- using System.Threading.Tasks;
-
- namespace CrendentialsTest
- {
- class Program
- {
- static void Main(string[] args)
- {
- MainAsync().Wait();
- Console.ReadKey();
- }
-
- static async Task MainAsync()
- {
- BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials("MyAccessKeyID", "MySecretAccessKey");
- AmazonSecurityTokenServiceClient stsClient = new AmazonSecurityTokenServiceClient(basicAWSCredentials);
- var getCallerIdentityResponse = await stsClient.GetCallerIdentityAsync(new GetCallerIdentityRequest());
- Console.WriteLine(getCallerIdentityResponse.Arn);
- }
- }
- }
Happy computing!