2 Answers
- Newest
- Most votes
- Most comments
0
I just tested this myself locally and it worked. @eginstockinger can you share the code you're using?
elizabsn$ node sample.js
Creating index:
{ acknowledged: true, shards_acknowledged: true, index: 'my-index' }
Adding document:
{
_index: 'my-index',
_id: '8wC2F4UBUrNWN66Pz6UQ',
_version: 1,
result: 'created',
_shards: { total: 0, successful: 0, failed: 0 },
_seq_no: 0,
_primary_term: 0
}
Here's the script I used (copied from docs and modified host and region:
var AWS = require('aws-sdk');
var aws4 = require('aws4');
var { Client, Connection } = require("@opensearch-project/opensearch");
var client = new Client({
node: 'https://xd3tlw1kvxtzaykzgxfh.us-east-1.aoss.amazonaws.com',
Connection: class extends Connection {
buildRequestObject (params) {
var request = super.buildRequestObject(params)
request.service = 'aoss';
request.region = 'us-east-1'; // e.g. us-east-1
var contentLength = '0';
if (request.headers['content-length']) {
contentLength = request.headers['content-length'];
request.headers['content-length'] = '0';
}
request.headers['x-amz-content-sha256'] = 'UNSIGNED-PAYLOAD';
request = aws4.sign(request, AWS.config.credentials);
request.headers['content-length'] = contentLength;
return request
}
}
});
async function index_document() {
// Create an index with non-default settings.
var index_name = "my-index";
var settings = "{ \"settings\": { \"number_of_shards\": 1, \"number_of_replicas\": 0 }, \"mappings\": { \"properties\": { \"title\": {\"type\": \"text\"}, \"director\": {\"type\": \"text\"}, \"year\": {\"type\": \"text\"} } } }";
var response = await client.indices.create({
index: index_name,
body: settings
});
console.log("Creating index:");
console.log(response.body);
// Add a document to the index
var document = "{ \"title\": \"Avatar\", \"director\": \"James Cameron\", \"year\": \"2003\" }\n";
var response = await client.index({
index: index_name,
body: document
});
console.log("Adding document:");
console.log(response.body);
}
index_document().catch(console.log);
answered a year ago
0
content-length is not supported with OpenSearch Serverless as per the limitation mentioned here: https://docs.aws.amazon.com/opensearch-service/latest/developerguide/serverless-clients.html#:~:text=You%20can%27t%20include%20Content%2DLength%20as%20a%20signed%20header%2C%20otherwise%20you%27ll%20get%20an%20invalid%20signature%20error
I have escalated to internal team and will fix the documents, meanwhile can you try without content-length header with javascript.
answered a year ago
Relevant content
- asked a year ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated a year ago
I'm having this same problem and I literally copy pasted your answer and still getting error.
Why I try your code exactly this is what comes out in the request header
I notice that the
SignedHeaders
inAuthorization
still includescontent-length