【发布时间】:2018-06-03 16:02:25
【问题描述】:
我必须调试有关 .net Core 和 AWS 的现有项目。 我们的项目在我们的 AWS 实例上运行良好,但我们无法在本地运行该项目。
首先我们收到了 AmazonServiceException: Unable to find credentials,但现在我们收到了消息:AmazonClientException: No RegionEndpoint or ServiceURL configured。我觉得这样更好。
我们的配置: 在我们的应用程序中,我们有 3 个 appsettings.{env.EnvironmentName}.json(开发、本地和生产)。我们知道默认情况下 VS 使用开发文件。 在我们的开发 appsettings 文件中,我们没有 AWS 对象,但在本地 appsettings 文件中,我们只有:
"AWS": {
"Region": "ap-southeast-2"
}
我们没有任何 web.config 或其他 json 配置文件。
我们尝试将凭证文件创建为:
[name of my IAM profile]
aws_access_key_id=accesskey
aws_secret_access_key=secretkey
region=ap-southeast-2
但我们没有找到如何使用它。
我们也尝试使用 dotnet core run 命令运行项目,并指定一些环境变量为:
export AWS_Region=ap-southeast-2
export AWS_ACCESS_KEY_ID=id
export AWS_SECRET_ACCESS_KEY=secret
export AWS_SESSION_TOKEN=token
export
AWS_CREDENTIAL_FILE=/Users/user/Developer/exemple/nameproject/G$
但同样的错误。
Program.cs 文件:
var host = new WebHostBuilder()
.UseKestrel(options => options.AddServerHeader = false)
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.UseUrls("http://*:9000")
.CaptureStartupErrors(true)
.Build();
host.Run();
启动文件(第一个函数):
public Startup(IHostingEnvironment env) {
// Configuration override https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", false, true)
.AddEnvironmentVariables();
Configuration = builder.Build();
// Shared startup configurator
CommonStartup = new CommonStartup(env, Configuration);
}
这是我们的问题: 我们项目的凭据在哪里或如何配置?
提前感谢您的回答。
【问题讨论】:
-
AWS SDK 会自动尝试查找 Access/Secret 密钥,因此将它们包含在您的 app.config 中就足够了。 app.config 中的密钥需要为“AWSAccessKey”和“AWSSecretKey”
-
感谢您的回答拉杰什。问题是这个项目中除了 3 个 appsettings.{env.EnvironmentName}.json 之外没有 appconfig。你能给我一个这个文件的例子吗?并且默认项目使用开发配置文件,我如何告诉它使用本地版本的appsettings?提前感谢您的回答。
-
当您使用配置构建器时,只需将它们添加到您的 json 中,它们就会流过。
-
我试图在我的 appsettings 文件中添加它:“AWS”:{“AccessKeyId”:“myaccesskey”,“SecretAccessKey”:“mysecretkey”,“Region”:“ap-southeast-2”但是我收到了消息:donet 意外退出(我在 mac 上)...
标签: .net amazon-web-services .net-core aws-sdk asp.net-core-webapi