Provide access credentials in application settings

How to read the access credentials.

Access credentials can be read from the file by using the App.Config file. These details can be picked up automatically from App.Config by using a default client declaration such as:


AmazonS3Config S3Config = new AmazonS3Config
{
  // replace below url with your endpoint url
  ServiceURL = "http://sample.endpointurl.com"
}
AmazonS3Client client = new Amazon.S3.AmazonS3Client(S3Config);

The AWSProfileName key declares the profile name and the AWSProfileLocation declares the location of the credentials file. The properties can be set as follows.


<configuration>
  <appSettings>
    <add key="AWSProfileName" value="development"/>
    <add key="AWSProfilesLocation" value="C:\aws_service_credentials\credentials"/>
  </appSettings>
</configuration>

The access credentials can then be read from the system properties as follows.


AWSCredentials credentials = new StoredProfileAWSCredentials("development");
IAmazonS3 s3Client = new AmazonS3Client(credentials);