适用于.NET的AWS开发工具包无法使用IIS访问凭据 [英] AWS SDK for .NET can't access credentials with IIS

查看:70
本文介绍了适用于.NET的AWS开发工具包无法使用IIS访问凭据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在访问SDK Store中的AWS凭证时遇到了一些麻烦,但这似乎仅是在IIS下运行时的问题.如果我通过使用ReSharper调用NUnit测试来达到相同的代码,则依赖项注入将起作用,并且S3客户端能够进行身份验证.

I'm having some trouble accessing the AWS credentials in the SDK Store, but it seems to only be a problem when running under IIS. If I hit the same code by invoking an NUnit test with ReSharper the dependency injection works and the S3 client is able to authenticate.

IAmazonS3 s3Client = new AmazonS3Client();

还有其他人遇到这个问题吗?您如何使依赖项注入起作用?

Has anyone else run into this problem? How were you able to get the dependency injection to work?

已建议将凭据文件方法与IIS一起使用,因为SDK存储会为每个用户以不同的方式加密凭据.如果我在我不想做的appSettings中对路径进行硬编码,则只能使凭据文件起作用.

The credential file approach has been recommended for use with IIS because the SDK Store encrypts the credentials differently for each user. I can only get a credentials file to work if I hard-code the path in the appSettings which I do not want to do.

除了以下路径之外,SDK还将在哪里寻找凭证文件?

Where would the SDK look for the credentials file besides the below paths?

C:\Users\<IIS_app_name>\.aws\credentials
C:\Users\<my_domain_user>\.aws\credentials

推荐答案

在Pavel的回答下回答了该问题,但我将发布一个答案,以使信息更易于使用.您可以在webLocal.config中指定凭据文件的位置(如果没有它,我将无法使其工作).部署应用程序后,凭据文件位置将是无效路径,并且SDK将故障转移到对EC2实例使用IAM角色.

The question was answered under Pavel's answer, but I'll post an answer to make the information easier to consume. You can specify the credentials file location in the webLocal.config (I wasn't able to get it to work without that). When the app is deployed, the credentials file location will be an invalid path, and the SDK will fail over to using the IAM role for the EC2 instance.

webLocal.config

<?xml version="1.0"?>
<appSettings>
    <!-- AWS -->
    <add key="AWSProfilesLocation" value="C:\Users\<IIS_app_name>\.aws\credentials" />
    <add key="AWSRegion" value="us-west-2" />
    <add key="S3Bucket" value="bucket." />
</appSettings>

当实例化不带参数的客户端时,依赖项注入将起作用.

The dependency injection will work when you instantiate a client without arguments.

IAmazonS3 s3Client = new AmazonS3Client();

这篇关于适用于.NET的AWS开发工具包无法使用IIS访问凭据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆