title: What is equivalent of DefaultAWSCredentialsProviderChain in C#
body: <p>While using <code>S3Client</code> in java, I used to initialize S3Client like this and it worked perfectly on local machine (where I have environment variables set) as well as EC2 instance (where I have IAM role):</p>
  
  <pre><code>AWSCredentials credentials = DefaultAWSCredentialsProviderChain.getInstance().getCredentials();
  AmazonS3 s3client = new AmazonS3Client(credentials);
  </code></pre>
  
  <p>I want to do the same in C#.net. For that, I have to use different methods to run it on local machine and EC2 instance.
  Right now, I am doing it somewhat like this :</p>
  
  <pre><code>var awsCredentials = new EnvironmentVariablesAWSCredentials(); //For local
  var awsCredentials2 = new InstanceProfileAWSCredentials(); //For EC2 instance 
  var awsRegion = Environment.GetEnvironmentVariable("AWS_REGION");
  AmazonS3Client s3Client = new AmazonS3Client(awsCredentials, RegionEndpoint.GetBySystemName(awsRegion));
  </code></pre>
  
  <p>I have gone through official <a href="https://docs.aws.amazon.com/sdk-for-net/v2/developer-guide/net-dg-config-creds.html" rel="nofollow noreferrer">AWS SDK for .Net's documentation</a></p>
  
  <p>But what I can not find is, equivalent of this <code>Java Method</code></p>
  
  <p><code>DefaultAWSCredentialsProviderChain.getInstance().getCredentials()</code></p>
  
  <p>Is there any method in C#.net that follows hierarchy of retrieving credentials and provide it?</p>
  
  <p>Thanks in advance.</p>