Himanshu
Himanshu

Reputation: 5

amazon web services cannot find credentials exception

When I run the following program, an exception occurs that cannot find the credentials

using (IAmazonS3 s3Client = new AmazonS3Client(RegionEndpoint.USWest2)) 
{                  
    PutObjectRequest request = new PutObjectRequest
    {
        BucketName = bucketName,
        Key = ps1,
        FilePath = path
    };

    PutObjectResponse response = s3Client.PutObject(request);
    richTextBox1.Text = response.ToString();
}

Also I have already configured the app.config like this:

<configuration>
   <appSettings>
      <add key="AWSProfileName" value="ashu"/>
      <add key="AWSProfilesLocation" value="C:\service_credential\credentials"/>
      <add key="AWSRegion" value="us-west-2" />
   </appSettings>
</configuration>

Upvotes: 0

Views: 858

Answers (1)

Joel R Michaliszen
Joel R Michaliszen

Reputation: 4222

You don't need to instantiate the client using new, the best approach to do this is using the AWSClientFactory and the StoredProfileAWSCredentials to create the clients.

SoredProfile approach, with this you must to have sure about the profile name and if it exists. Whatever see this example that show you how figure out: https://blogs.aws.amazon.com/net/post/Tx1310VG2O81PSY/Referencing-Credentials-using-Profiles

var credentials = new StoredProfileAWSCredentials("ashu");

EnvirementCredential Approach, with this you must to put the AWSAccessKey and AWSSecretKey into the App.config/Web.config, and must to be sure about that and the region was correct.

App.config

<appSettings>
        <add key="AWSAccessKey" value="Access_KEY" />
        <add key="AWSSecretKey" value="Secret_KEY" />      
</appSettings>

var credentials = new EnvironmentAWSCredentials();

using (IAmazonS3 s3Client = AWSClientFactory.CreateAmazonS3Client(credentials, RegionEndpoint.USWest2)) 
{                  
    PutObjectRequest request = new PutObjectRequest
    {
        BucketName = bucketName,
        Key = ps1,
        FilePath = path
    };

    PutObjectResponse response = s3Client.PutObject(request);
    richTextBox1.Text = response.ToString();
}

Upvotes: 1

Related Questions