我试图找到一个如何连接到 node.js 中的 AWS ES 实例的示例,然后通过一个简单的请求访问 ES 集群。
我正在尝试使用elasticsearch node package以及一个名为http-aws-es的开源插件来执行此操作。
我已将我的 aws ES 访问策略配置为如下所示:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::<account-id>:root"
},
"Action": "es:*",
"Resource": "example-domain.us-east-1.es.amazonaws.com:<account-id>:domain/*"
},
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "es:*",
"Resource": "example-domain.us-east-1.es.amazonaws.com:<account-id>:domain/*",
"Condition": {
"IpAddress": {
"aws:SourceIp": "<my-ip>"
}
}
}
]
}
因此,我希望能够从 ip 地址或链接到我的 aws 帐户的 IAM 用户对 es 实例发出 put 和 get 请求。
我有以下代码在 node.js 中尝试此操作:
var aws_access_key = 'example';
var aws_secret_key = 'key';
var es = require('elasticsearch').Client({
hosts: 'example-domain.us-east-1.es.amazonaws.com',
connectionClass: require('http-aws-es'),
amazonES: {
region: 'us-east-1',
accessKey: aws_access_key,
secretKey: aws_secret_key
}
});
es.ping({
// ping usually has a 3000ms timeout
requestTimeout: Infinity,
// undocumented params are appended to the query string
hello: "elasticsearch!"
}, function (error) {
if (error) {
console.log(error);
console.trace('elasticsearch cluster is down!');
} else {
console.log('All is well');
}
});
当前返回授权错误:
{ [Error: Authorization Exception]
status: 403,
displayName: 'AuthorizationException',
message: 'Authorization Exception' }
我还没有看到通过在 node.js 中使用签名策略来使用 aws ES 实例的工作示例。有人有见解吗?