连接到Elasticsearch-Amazon Elasticsearch Service-IAM用户 [英] Connecting to Elasticsearch - Amazon Elasticsearch service - IAM user
问题描述
我选择了允许访问一个或多个AWS账户或IAM用户
I have selected "Allow access to one or more AWS accounts or IAM users"
我的访问策略
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::12345678910:user/elastic"
},
"Action": "es:*",
"Resource": "arn:aws:es:eu-west-1:123456789:domain/elastic-cluster/*"
}
]
}
我已经创建了IAM配置文件-
I have created an IAM profile -
user - elastic
password -hisdfdsfds
Access key Id - sdsfdssdfdsfdsfdsfsdfsd
Secret Access Key - sdsfdsfdsfsdfdsfds
当我尝试连接
$params = array();
$params['hosts'] = array (
'search-elastic-cluster-sdfsdfsdfs.eu-east.es.amazonaws.com:80',
);
$client = new Elasticsearch\Client($params);
它会引发以下错误:
{"Message":"User: anonymous is not authorized to perform: es:ESHttpPost on resource: arn:aws:es:eu-west-1:dsfdsfsdfsdsd:domain/elastic-cluster/sdsfsfds/sdfdsfdssd/_search"}
我发现可以通过已签名的版本4签名请求进行访问。我尝试这样做,但是不能。
I found it can be accessed by signed version 4 signature requests. I tried doing it, but could not . Maybe the way is wrong.
如果有人在创建对Elasticsearch域的签名版本4请求中提出建议,我会很高兴。使用我上面所述的参数的示例将非常有帮助。
I would be happy if some one suggests ideas in creating signed version 4 request to elasticsearch domain. An example using parameters I stated above would be very helpful. Thanks in advance.
推荐答案
应用程序需要签署去往Elasticsearch的请求。适用于您选择的语言的AWS开发工具包应具有创建签名请求的凭证的方法。
The application needs to sign the requests going to Elasticsearch. The AWS SDK for your language of choice should have a method which creates the credentials for the sign request.
当您向您的请求提供凭证时,应该可以
When you provide your requests with the credentials, it should be ok and good to go.
这是使用javascript sdk的代码段:
This is a code snippet using the javascript sdk:
var AWS = require('aws-sdk');
var creds = new AWS.EnvironmentCredentials('AWS');
var esDomain = {
region: 'us-east-1',
endpoint: 'yoursearchdomain.region.amazonaws.com',
index: 'myindex',
doctype: 'mytype'
};
var endpoint = new AWS.Endpoint(esDomain.endpoint);
var req = new AWS.HttpRequest(endpoint);
req.method = 'POST';
req.path = path.join('/', esDomain.index, esDomain.doctype);
req.region = esDomain.region;
req.headers['presigned-expires'] = false;
req.headers['Host'] = endpoint.host;
req.headers['Content-Type'] = 'application/json';
req.body = doc;
var signer = new AWS.Signers.V4(req , 'es');
signer.addAuthorization(creds, new Date());
var send = new AWS.NodeHttpClient();
send.handleRequest(req, null, function(httpResp) {
var respBody = '';
httpResp.on('data', function (chunk) {
respBody += chunk;
});
httpResp.on('end', function (chunk) {
console.log('Response: ' + respBody);
context.succeed('Lambda added document ' + doc);
});
}, function(err) {
console.log('Error: ' + err);
context.fail('Lambda failed with error ' + err);
});
这篇关于连接到Elasticsearch-Amazon Elasticsearch Service-IAM用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!