在 IIS 下 运行 时无法连接到 Elasticsearch(不遵守访问密钥和机密)
Can't connect to Elasticsearch (access key & secret not being respected) when running under IIS
我正在使用 ElasticClient C# class 连接到托管在 AWS 上的 Elasticsearch 实例。
var pool = new SingleNodeConnectionPool(new Uri(Url));
var httpConnection = new AwsHttpConnection(Region);
var config = new ConnectionSettings(pool, httpConnection)
.PrettyJson()
.DisableDirectStreaming()
.DefaultTypeName(TYPE)
.DefaultIndex(INDEX);
_client = new ElasticClient(config);
为了设置访问密钥和秘密,我在 Windows 计算机上存储了一个凭据文件:C:\Users\{username}\.aws\credential。它有一个 "default" 条目,因此不需要手动设置配置文件名称。当我 运行 我的 ASP.NET 核心 Web 应用程序将启动设置为项目时,这工作正常。
但是,一旦我更改为启动:IIS...
...然后 Elasticsearch 连接失败。每当我尝试执行查询时,它都会出错:
Message=Invalid NEST response built from a unsuccessful low level
call on POST: /{url1}/{url2}/_search?pretty=true&typed_keys=true
Audit trail of this API call:
- 1 BadRequest: Node: https://{url1}.us-east-1.es.amazonaws.com/ Took: 00:00:00.0090414
OriginalException: System.Net.Http.HttpRequestException: A socket operation was attempted to an unreachable network --->
System.Net.Sockets.SocketException: A socket operation was attempted
to an unreachable network
IIS 网站是 运行 一个应用程序池,设置为使用我的 Windows 帐户。显然,它在 IIS 下 运行ning 时忽略了 .aws 凭据。我还尝试使用 AWS Explorer Visual Studio 2017 扩展创建配置文件,"default" 以及自定义命名的一个。
我尝试在我的 ASP.NET 核心项目中安装 AWSSDK.Extensions.NETCore.Setup nuget 包,并在 appsettings.json 中指定自定义命名配置文件,两者都是这样的:
"AWS": {
"Profile": "local-dev-profile",
"Region": "us-east-1"
}
像这样:
"AppSettings": {
"AWSProfileName": "local-dev-profile",
},
都不起作用,我仍然得到相同的 "A socket operation was attempted to an unreachable network" 错误。我已经遵循了所有 AWS 指南,感觉我做的是正确的,但它在 IIS 下不起作用。任何帮助将不胜感激。
由于某种原因,当 运行在 IIS 下使用它时,它没有像往常那样提取访问密钥和秘密,这可能与
中发生的魔法有关=15=] IIS下的核心到运行。我不得不将密钥添加到我的 launchSettings.json 文件中,而不是让它在 IIS 中工作(它被复制为 ENVIRONMENT_VARIABLES 到 web.config。)
launchSettings.json 中的 IIS 配置文件如下所示:
"MobileApi IIS (DEV)": {
"commandName": "IIS",
"launchUrl": "{url}",
"environmentVariables": {
"AWS_SECRET_ACCESS_KEY": "{value}",
"AWS_ACCESS_KEY_ID": "{value}",
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "{url}"
},
我正在使用 ElasticClient C# class 连接到托管在 AWS 上的 Elasticsearch 实例。
var pool = new SingleNodeConnectionPool(new Uri(Url));
var httpConnection = new AwsHttpConnection(Region);
var config = new ConnectionSettings(pool, httpConnection)
.PrettyJson()
.DisableDirectStreaming()
.DefaultTypeName(TYPE)
.DefaultIndex(INDEX);
_client = new ElasticClient(config);
为了设置访问密钥和秘密,我在 Windows 计算机上存储了一个凭据文件:C:\Users\{username}\.aws\credential。它有一个 "default" 条目,因此不需要手动设置配置文件名称。当我 运行 我的 ASP.NET 核心 Web 应用程序将启动设置为项目时,这工作正常。
但是,一旦我更改为启动:IIS...
...然后 Elasticsearch 连接失败。每当我尝试执行查询时,它都会出错:
Message=Invalid NEST response built from a unsuccessful low level call on POST: /{url1}/{url2}/_search?pretty=true&typed_keys=true
Audit trail of this API call:
- 1 BadRequest: Node: https://{url1}.us-east-1.es.amazonaws.com/ Took: 00:00:00.0090414
OriginalException: System.Net.Http.HttpRequestException: A socket operation was attempted to an unreachable network --->
System.Net.Sockets.SocketException: A socket operation was attempted to an unreachable network
IIS 网站是 运行 一个应用程序池,设置为使用我的 Windows 帐户。显然,它在 IIS 下 运行ning 时忽略了 .aws 凭据。我还尝试使用 AWS Explorer Visual Studio 2017 扩展创建配置文件,"default" 以及自定义命名的一个。
我尝试在我的 ASP.NET 核心项目中安装 AWSSDK.Extensions.NETCore.Setup nuget 包,并在 appsettings.json 中指定自定义命名配置文件,两者都是这样的:
"AWS": {
"Profile": "local-dev-profile",
"Region": "us-east-1"
}
像这样:
"AppSettings": {
"AWSProfileName": "local-dev-profile",
},
都不起作用,我仍然得到相同的 "A socket operation was attempted to an unreachable network" 错误。我已经遵循了所有 AWS 指南,感觉我做的是正确的,但它在 IIS 下不起作用。任何帮助将不胜感激。
由于某种原因,当 运行在 IIS 下使用它时,它没有像往常那样提取访问密钥和秘密,这可能与
中发生的魔法有关=15=] IIS下的核心到运行。我不得不将密钥添加到我的 launchSettings.json 文件中,而不是让它在 IIS 中工作(它被复制为 ENVIRONMENT_VARIABLES 到 web.config。)
launchSettings.json 中的 IIS 配置文件如下所示:
"MobileApi IIS (DEV)": {
"commandName": "IIS",
"launchUrl": "{url}",
"environmentVariables": {
"AWS_SECRET_ACCESS_KEY": "{value}",
"AWS_ACCESS_KEY_ID": "{value}",
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "{url}"
},