Reputation: 885
I have an elasticsearch cluster running on AWS. I need to connect with elasticsearch cluster with Angular 6, what is the best way to achieve this ?. I have an access key & secret key and I have an access policy in elasticsearch that allows this user with full access. I use this below code in NodeJs.
var client = new elasticsearch.Client({
host: process.env.ES_ENDPOINT,
connectionClass: require('http-aws-es'),
amazonES: {
region: process.env.ES_REGION,
credentials: new AWS.EnvironmentCredentials('AWS')
},
log: 'trace'
});
I want to do the same with Angular 6. I have connected without authentication like given below code:-
this.client = new Client({
host: 'https://search-usercluster-xxxyuyy.ap-south-1.es.amazonaws.com/',
log: 'trace'
});
Upvotes: 0
Views: 820
Reputation: 151
The best way to achieve this is to use Amazon Cognito. For example:
import AWS from 'aws-sdk';
AWS.config.region = 'us-east-2';
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'YOUR_IDENTITY_POOL_ID'
});
const options = {
hosts: [
'YOUR_HOST_URL'
], // array of amazon es hosts (required)
connectionClass: require('http-aws-es'), // use this connector (required)
amazonES: AWS.config, // set an aws config e.g. for multiple clients to different regions
log: 'trace'
};
const es = require('elasticsearch').Client(options);
UPD: Added import AWS from 'aws-sdk', we need to know how to get the aws.config access. Thank you @AravinthanM!
Upvotes: 1