所以我有一个 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>
此文件的构建操作是“嵌入式资源”,我也尝试将其更改为“内容”,但没有帮助。
一些可能相关也可能不相关的事情:
我正在使用 ILMerge
将 AWSSDK.dll
(以及其他)合并到 exe
中,然后我运行该文件通过命令行创建 Amazon EC2 实例。
最佳答案
需要考虑的事情,无论是针对这个特定问题还是 future ,如果您创建一个 IAM 角色,为其分配一组权限,然后使用该 IAM 角色启动您的 EC2 实例,访问 key 将自动提供给 SDK而且您不必像现在这样冒险将它们存储在配置文件中。
关于c# - 适用于 C# 的 AWS SDK,将 App.config 文件放在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20292580/