Programmatically get your AWS Account ID with .NET

Want to learn more about AWS Lambda and .NET? Check out my A Cloud Guru course on ASP.NET Web API and Lambda.

Here is a quick way to get your AWS Account ID with .NET

First, add the AWSSDK.SecurityToken package to your project.

Then it’s just a few lines of code -

using Amazon.SecurityToken; 

AmazonSecurityTokenServiceClient client = new AmazonSecurityTokenServiceClient();

var response = await client.GetCallerIdentityAsync(new Amazon.SecurityToken.Model.GetCallerIdentityRequest());
Console.WriteLine(response.Account);

Hope this saves someone a few hours!

comments powered by Disqus

Related