Why can't the AWS SDK find my credentials? - c#

I have a server that utilizes AWS SES to send notification emails, but I keep recieving the following message:
An unhandled exception of type 'Amazon.Runtime.AmazonServiceException'
occurred in AWSSDK.dll
Additional information: Unable to find credentials
I have a credentials file fully accessible by the server's user and I use the following to tell the AWS SDK where the file is located and the profile name:
AWSConfigs.AWSProfileName = "example-user";
AWSConfigs.AWSProfilesLocation = Environment.CurrentDirectory + "/example-dir/credentials";
..however crashes at the following line with the error message:
AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(REGION);
I checked out this answer on Amazon.Runtime.AmazonServiceException: Unable to find credentials which suggests that profiles should be in the application's configuration file, like so:
<appSettings>
<add key="AWSProfilesLocation" value="C:\awsfile\credentials" />
<add key="AWSRegion" value="us-east-1" />
</appSettings>
...this results in the exact same error.
What am I doing wrong? The AWSConfigs.* code has been working for around six months now without issue, this started happening when my project took a hiatus and I restored it from its Git repository. I cannot remember which version of Visual Studio I used before but I'm currently using 2015 (update 3).
I did however get this to work by adding the credentials as system environment variables, but this isn't a permanent solution for security reasons.
If I download earlier commits, build them and run them, I get the exact same error. I'm thinking this is either something to do with the version of Visual Studio I'm using, but can't think of any reasons why this could be.
The AWS SDK and .NET versions have always been the same so it shouldn't be incompatibility (2.3.55.2 for the AWS SDK and .NET 4.6.1).

If you are running applications on an Amazon EC2 instance and those applications require AWS credentials, the best-practice advice is:
Never put credentials in your code
Assign an IAM Role to the instance and the SDK will automatically use those credentials
Even when you're running an application on a non-EC2 instance, avoid putting credentials in code. Instead, put them in environment variables or configuration files.
See: Configuring AWS Credentials for .Net applications

Related

Is there a way to provide IIS with the location of a DLL that your MVC solution depends on?

I am building an application that scaffolds a SSIS package using EzAPI (Version 0.8.5). The code runs perfect within visual studio, no errors or bugs until I publish the MVC application (.NET 4.5) to the IIS server (Version 10.0.14298). This is when the function fails and doesn't save the package. The following error is thrown on save:
{"The system cannot find the file specified. (Exception from HRESULT:
0x80070002)":null} source: Microsoft.SqlServer.ManagedDTS
I have ensured that SSIS, Integration services have been installed on the IIS server, exact same version as my local instance MSSQL2017 so the DLL's I require are all in the same folders. I deployed to my local instance of IIS and get the same error as well.
using Microsoft.SqlServer.SSIS.EzAPI;
EzPackage _package = new EzPackage() { Name = "Package" };
_package.SaveToFile(#"C:\Package.dtsx"); // Fails here with error
The expectation would be that the package would be generated and then I would be able to view it within the C drive but it looks like it fails when it tries to build / finalize the package
Stack Trace:
" at Microsoft.SqlServer.Dts.Runtime.Package.SaveToXML(String&
packageXml, IDTSEvents events)\r\n at
Microsoft.SqlServer.SSIS.EzAPI.EzPackage.SaveToXML(IDTSEvents
events)\r\n at
Microsoft.SqlServer.SSIS.EzAPI.EzPackage.SaveToFile(String
fileName)\r\n at method(ViewModel model) in Logic.cs:line 641"
Try creating a folder in C:. For example, C:\packages. Make sure the app pool user has read/write access to the folder. Try adding IUSR or the app pool ( IIS AppPool\ApplicationPoolName ) user to the C:\packages folder with read write permissions.

AmazonS3Client constructor in .Net Core throws when running under NETWORK_SERVICE (service fabric)

I need to upload some data to the S3 storage using dotnet-core service in the service fabric cluster (which is running as NETWORK_SERVICE).
In this scenario I am not able to construct the AmazonS3Client.
var s3 = new AmazonS3Client(awsAccountKey, awsSecret, RegionEndpoint.EUCentral1);
Throws:
System.TypeInitializationException: 'The type initializer for 'Amazon.Runtime.Internal.DeterminedCSMConfiguration' threw an exception.'
Inner exception:
UnauthorizedAccessException: Access to the path 'C:\WINDOWS\system32\config\systemprofile' is denied.
I am using nugets:
AWSSDK.S3 Version="3.3.24.3"
AWSSDK.Core Version="3.3.27"
The code runs OK:
Under dotnet framework 4.6.2 (net462) (in the same service fabric cluster)
Under dotnet core, but run under regular user (not in service fabric)
Questions:
Is it OK to use the AWS SDK nugets in dotnet core?
What is the constructor looking for in C:\WINDOWS\system32\config\systemprofile folder? I provided account key and secret, shouldn't it be enough?
Is there some setting I am missing to workaround the issue?
The AWS SDK is a dot net standart package that should work fine on Full Framework or DotNet Core, you can confirm that when you ran the application on your machine and it worked.
C:\WINDOWS\system32\config\systemprofile is a folder used to store system profile information, similar to fodlers like C:\users\username\,
I would assume it is trying to load or save something in there because it is running as NetWork Service and is failing, I would try:
Run the service as a local user in SF, instead of Network Service
Check if all files are being copied correclty
use the AmazonS3Client that receives an explicit AmazonS3Config instead
Check if the DotNet core is installed in the server and the version in there is compatible with the one you are using
Looks like it is a bug in AWSSDK.Core: https://github.com/aws/aws-sdk-net/issues/1097

Google Speech - After Hosting getting Unauthenticated Error

I have created a web api method to Speech to text using Google Speech library. It is working fine when I execute using the visual studio. After hosting the application on IIS, I am getting below error when the api method is called
Method:Status(StatusCode=Unauthenticated, Detail="Getting metadata from plugin failed with error: Exception occurred in metadata credentials plugin.")
Error at line with code:
var speechResponse = speech.Recognize(SpeechConfig,
RecognitionAudio.FromFile(fileToProcess));*
And on another system, I have configured the GOOGLE_APPLICATION_CREDENTIALS env avariable with service account json, but I am getting below error
The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials.
Do you also have compact framework sdk installed for visual studio? if try adding
< NoStdLib > False< / NoStdLib >
in your *.csproj file. This would force VS to use the std mscorlib.dll instead of compact one.
Check if the date and time on your system are correct (should be with 60 seconds of actual time)

Error while using Amazon .NET SDK

I installed .NET SDK and in Visual Studio, selected New Project -> AWS -> Storage and Content Delivery -> AWS S3 Sample. Given below is my code.
using (client = Amazon.AWSClientFactory.CreateAmazonS3Client())
{
ListBucketsResponse response = client.ListBuckets();
}
My app.config has 3 values:
<add key="AWSAccessKey" value="xxxx"/>
<add key="AWSSecretKey" value="xxxxxxxx"/>
<add key="AWSRegion" value="us-east-1"/>
I get following exception at the statement:
ListBucketsResponse response = client.ListBuckets();
Exception
The request signature we calculated does not match the signature you provided. Check your key and signing method.
Inner Exception
The remote server returned an error: (403) Forbidden.
Please help.
Not sure if you figured this out yet, but I can confirm that your code is working 100% when I substitute my credentials instead.
If you are sure your credentials are correct, then make sure you have the newest .net sdk installed and try again - just tried it myself with version 2.0.15.1 available here:
http://sdk-for-net.amazonwebservices.com/latest/AWSToolsAndSDKForNet.msi
and it works as expected.

Unable to find requested .Net framework data provider. It may not be installed

I am using VS2010 Express and trying to create a new connection with the help of server explorer. i selected the server name and windows authentication.
After it i mentioned the name of database to be connected with and tested connection successfully but as i click on ok it shows me error
"Unable to find requested .Net framework data provider.It may not be installed"
i have all the required dll's in my reference of project such as system.data,system.data.entity but still it is giving error somebody please help me.
It's probably your config file...Check your config files for self terminating nodes.

Categories