Я использую тот же метод подписи, который описан в Подписание HTTP-запросов в сервис Amazon Elasticsearch . Подписание отлично работает с документами, в которых есть поля на английском языке, но нет других языков.
Я пытался добавить UTF-8 в тип контента, но это не помогло.
// If your credentials don't work, export them at the terminal using the following commands:
// export AWS_ACCESS_KEY_ID="your-access-key"
// export AWS_SECRET_ACCESS_KEY="your-secret-key"
var AWS = require('aws-sdk');
var region = ''; // e.g. us-west-1
var domain = ''; // e.g. search-domain.region.es.amazonaws.com
var index = 'node-test';
var type = '_doc';
var id = '1';
var json = {
"title": "عربي",
"director": "Bennett Miller",
"year": "2011"
}
indexDocument(json);
function indexDocument(document) {
var endpoint = new AWS.Endpoint(domain);
var request = new AWS.HttpRequest(endpoint, region);
request.method = 'PUT';
request.path += index + '/' + type + '/' + id;
request.body = JSON.stringify(document);
request.headers['host'] = domain;
request.headers['Content-Type'] = 'application/json';
// charset doesn't work too
// request.headers['Content-Type'] = 'application/json; charset=utf-8';
// Content-Length is only needed for DELETE requests that include a request
// body, but including it for all requests doesn't seem to hurt anything.
request.headers["Content-Length"] = request.body.length;
var credentials = new AWS.EnvironmentCredentials('AWS');
var signer = new AWS.Signers.V4(request, 'es');
signer.addAuthorization(credentials, new Date());
var client = new AWS.HttpClient();
client.handleRequest(request, null, function(response) {
console.log(response.statusCode + ' ' + response.statusMessage);
var responseBody = '';
response.on('data', function (chunk) {
responseBody += chunk;
});
response.on('end', function (chunk) {
console.log('Response body: ' + responseBody);
});
}, function(error) {
console.log('Error: ' + error);
});
}
С приведенным выше кодом я получаю:
403 Forbidden
Response body: {
"message": "The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details."
}