10

we designed the WebService application in vs 2010 using AWS SDK toolkit which connect to AWS SNS Service.

It Perfectly works when we directly run from VS 2010 Development studio, but when we publish webservice to Local IIS or dedicated webserver it fails with following error Messages.

Amazon.Runtime.AmazonServiceException: Unable to find credentials

Exception 1 of 4:
System.ArgumentException: Path cannot be the empty string or all whitespace.
Parameter name: path
   at System.IO.Directory.GetParent(String path)
   at Amazon.Runtime.StoredProfileAWSCredentials.DetermineCredentialsFilePath(String profilesLocation)
   at Amazon.Runtime.StoredProfileAWSCredentials..ctor(String profileName, String profilesLocation)
   at Amazon.Runtime.EnvironmentAWSCredentials..ctor()
   at Amazon.Runtime.FallbackCredentialsFactory.<Reset>b__1()
   at Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(Boolean fallbackToAnonymous)

Exception 2 of 4:
System.ArgumentException: Path cannot be the empty string or all whitespace.
Parameter name: path
   at System.IO.Directory.GetParent(String path)
   at Amazon.Runtime.StoredProfileAWSCredentials.DetermineCredentialsFilePath(String profilesLocation)
   at Amazon.Runtime.StoredProfileAWSCredentials..ctor(String profileName, String profilesLocation)
   at Amazon.Runtime.FallbackCredentialsFactory.<Reset>b__2()
   at Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(Boolean fallbackToAnonymous)

Exception 3 of 4:
System.InvalidOperationException: The environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY were not set with AWS credentials.
   at Amazon.Runtime.EnvironmentVariablesAWSCredentials..ctor()
   at Amazon.Runtime.FallbackCredentialsFactory.<Reset>b__3()
   at Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(Boolean fallbackToAnonymous)

Exception 4 of 4:
Amazon.Runtime.AmazonServiceException: Unable to reach credentials server
   at Amazon.Runtime.InstanceProfileAWSCredentials.GetContents(Uri uri)
   at Amazon.Runtime.InstanceProfileAWSCredentials.<GetAvailableRoles>d__0.MoveNext()
   at Amazon.Runtime.InstanceProfileAWSCredentials.GetFirstRole()
   at Amazon.Runtime.FallbackCredentialsFactory.<Reset>b__4()
   at Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(Boolean fallbackToAnonymous)
   at Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(Boolean fallbackToAnonymous)
   at Amazon.SimpleNotificationService.AmazonSimpleNotificationServiceClient..ctor()
   at CellicaAwsSnsService..ctor()
   at Service..ctor()
Sayse
  • 42,633
  • 14
  • 77
  • 146
YogeshNC
  • 311
  • 1
  • 2
  • 12
  • hi, did you check if web service URL is accessible from your web server? sometimes the firewall blocks it – sankoobaba Apr 10 '15 at 09:37
  • yes i checked it, also its not working in Local IIS, when i publish this to LOCAL IIS, same error given. – YogeshNC Apr 10 '15 at 09:40

2 Answers2

17

Create a credentials file at any path where you can access this path from web service application e.g. C:\awsfile\credentials but remember don't give any extension this file File should contains following data.

[default]
aws_access_key_id=[your_access_key]
aws_secret_access_key=[your_secret_key]

After this you need to set the path in appsetting tag in the Web.config file:

<appSettings>
<add key="AWSProfilesLocation" value="C:\awsfile\credentials" />
<add key="AWSRegion" value="us-east-1" />
</appSettings>
Mahdi
  • 3,199
  • 2
  • 25
  • 35
YogeshNC
  • 311
  • 1
  • 2
  • 12
2

In AWS Explorer for Visual Studio you can create user profiles that give you different permissions on AWS, then you can choose which profile you want to use in AWS Explorer. These profiles are available only to your Windows user account, if anyone else uses your computer then they will have to create their own profiles. Any software that you run under your user account can also use these profiles.

If you don't configure your application to use a specific profile then it will use the default profile.

This problem occurs because IIS runs under a different user account than the one you are logged into, and therefore does not have access to your AWS profiles.

There are several ways to tell your application which AWS profile to use when it runs (see http://docs.aws.amazon.com/sdk-for-net/v2/developer-guide/net-dg-config-creds.html). The simplest option for developers is to create a credentials file and reference that file from web.config. For example if you create a file called C:\aws\credentials you can tell your application to use profile2 from this credentials file by adding this to your web.config file.

<configuration>

  <configSections>
    <section name="aws" type="Amazon.AWSSection, AWSSDK.Core" />
  </configSections>

  <aws 
    region="us-east-1" 
    profileName="profile2"
    profilesLocation="C:\aws\credentials" />

</configuration>

The content of the credentials file should be similar to this:

[profile1]
aws_access_key_id = {accessKey}
aws_secret_access_key = {secretKey}

[profile2]
aws_access_key_id = {accessKey}
aws_secret_access_key = {secretKey}

To get an access key and a secret key go to the AWS IAM console at https://console.aws.amazon.com/iam/home?region=us-east-1#/users choose the user you want your application to run as, then click on the "Security Credentials" tab then click the "Create Access Key" button.

bikeman868
  • 2,236
  • 23
  • 30