Good afternoon,
Some days I try to connect with OpenSearch without success with NodeJS.
I tried following the documentation but it only worked using aws_access_key_id and aws_secret_access_key
https://docs.aws.amazon.com/en_br/opensearch-service/latest/developeguide/request-signing.html#request-signing-node
I have a NodeJS backend running inside AWS EKS and the same if I connect the roles through a Service Account:
RoleName: MyService
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::999999999999:oidc-provider/oidc.eks.sa-east-1.amazonaws.com/id/XXXXXXXXXXXXXXXX"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"oidc.eks.sa-east-1.amazonaws.com/id/XXXXXXXXXXXXXXXX:sub": "system:serviceaccount:default:YYYYYYYYYYYYYYYYYY",
"oidc.eks.sa-east-1.amazonaws.com/id/XXXXXXXXXXXXXXXX:aud": "sts.amazonaws.com"
}
}
}
]
}
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"es:*"
],
"Resource": "*"
}
]
}
NodeJs
const { Client } = require('@opensearch-project/opensearch');
const { defaultProvider } = require('@aws-sdk/credential-provider-node');
const createAwsOpensearchConnector = require('aws-opensearch-connector');
const getClient = async () => {
const host = 'https://search-mydb-fpg5d4YHAYHAYAHAmvuyr3m.sa-east-1.es.amazonaws.com'
const awsCredentials = await defaultProvider()();
const connector = createAwsOpensearchConnector({
credentials: awsCredentials,
region: 'sa-east-1',
getCredentials: function (cb) {
return cb();
},
});
return new Client({
...connector,
node: `https://${host}`,
});
};
I have received the following error message.
CredentialsProviderError: Role Arn ‘arn:aws:iam::9999999999:role/XXXXXXXXX’ needs to be assumed with web identity, but no role assumption callback was provided
Can anyone connect in NodeJs, do you have an example using these same settings?