c# - 适用于 C# 的 AWS SDK,将 App.config 文件放在哪里?

标签 c# amazon-web-services amazon-s3

所以我有一个 C# 控制台应用程序可以将文件上传到 s3 存储。

当我从 Visual Studio 内部调试它时,它工作正常,但是,当我构建 .exe 并在我的服务器上运行它时,我收到错误消息,指出它无法在 App.config 文件中找到访问 key 。

System.ArgumentException: Access Key could not be found.  Add an appsetting to your App.config with the name AWSAccessKey with a value of your access key.

还有:

Amazon.Runtime.AmazonServiceException: Unable to reach credentials server

第二个错误可能是由第一个引起的。

我的 App.config 文件与我正在运行的 .exe 位于同一目录中,但这没有帮助。

我还需要做什么?

这是我的 App.config 文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="AWSAccessKey" value="key"/>
    <add key="AWSSecretKey" value="secret"/>
    <add key="AWSRegion" value="us-west-2" />
  </appSettings>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

此文件的构建操作是“嵌入式资源”,我也尝试将其更改为“内容”,但没有帮助。


一些可能相关也可能不相关的事情:

我正在使用 ILMergeAWSSDK.dll(以及其他)合并到 exe 中,然后我运行该文件通过命令行创建 Amazon EC2 实例。

最佳答案

需要考虑的事情,无论是针对这个特定问题还是 future ,如果您创建一个 IAM 角色,为其分配一组权限,然后使用该 IAM 角色启动您的 EC2 实例,访问 key 将自动提供给 SDK而且您不必像现在这样冒险将它们存储在配置文件中。

http://aws.typepad.com/aws/2012/06/iam-roles-for-ec2-instances-simplified-secure-access-to-aws-service-apis-from-ec2.html

关于c# - 适用于 C# 的 AWS SDK,将 App.config 文件放在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20292580/

相关文章:

amazon-web-services - AWS Cloudformation 上的 Content-Type 出现错误

python - 仅从多个文件夹的 s3 存储桶中读取特定的 json 文件

amazon-web-services - Amazon S3 和 Amazon EBS 之间的主要区别是什么

maven - 如何使用 Maven 将 Artifact 部署到 Amazon S3 中?

c# - 为什么Angular的请求头修改会抛出option 401错误

c# - 字节数组到字数组到字符串

node.js - 从 DynamoDB 检索值

c# - 为什么分组连接的结果重复 2 次?

c# - .NET Winforms DataGridView - 任何嵌套方式?

java - 如何将 Excel 文件从 AWS S3 存储桶获取到 Java 中的 MultipartFile 中