AWS Elastic Search与Kibana集成后,如果使用IP策略或资源策略进行身份验证,则会发现并不起作用。此时可以尝试使用AWS Cognito或AWS IAM策略进行身份验证。
以使用AWS Cognito为例,首先需要创建一个用户池。假设创建了名为“my-user-pool”的用户池,可以使用以下代码示例进行身份验证:
const AWS = require('aws-sdk'); const AmazonCognitoIdentity = require('amazon-cognito-identity-js');
const credentials = new AWS.CognitoIdentityCredentials({ IdentityPoolId: 'YOUR_IDENTITY_POOL_ID' });
AWS.config.update({ credentials: credentials });
const poolData = { UserPoolId: 'YOUR_USER_POOL_ID', ClientId: 'YOUR_APP_CLIENT_ID' }; const userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
const authenticationData = { Username: 'YOUR_USERNAME', Password: 'YOUR_PASSWORD' }; const authenticationDetails = new AmazonCognitoIdentity.AuthenticationDetails( authenticationData );
const userData = { Username: 'YOUR_USERNAME', Pool: userPool }; const cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
cognitoUser.authenticateUser(authenticationDetails, { onSuccess: () => console.log('Authentication succeeded'), onFailure: (err) => console.error('Authentication failed: ', err.message), });
其中,需要替换YOUR_IDENTITY_POOL_ID、YOUR_USER_POOL_ID、YOUR_APP_CLIENT_ID、YOUR_USERNAME和YOUR_PASSWORD为对应的值。
通过AWS Cognito进行身份验证后,即可在AWS Elastic Search with Kibana中进行正常操作。