Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authenticating elastic search client from lambda broken in 2.382.0 #2469

Closed
wheresrhys opened this issue Jan 3, 2019 · 3 comments
Closed
Labels
closing-soon This issue will automatically close in 4 days unless further comments are made. guidance Question that needs advice or information.

Comments

@wheresrhys
Copy link

Since upgrading to 2.382.0 calls to ES from my lambda have stopped working, throwing the following error.

message:	 AWS credentials not provided	
    	 stack:	 Error: AWS credentials not provided
    at getEsClient (/var/task/dist/lib/es-client.js:26:11)
    at Object.search (/var/task/dist/lib/es-client.js:44:10)
    at searchPage (/var/task/dist/searchHandler.js:104:36)
    at Promise.resolve.then.then.isSignedIn (/var/task/dist/lib/lambda.js:125:12)
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:228:7)	
    	 type:	 Error	

Downgrading to 2.381.0 fixes the issue

Here is my es client code (all dependencies on latest versions):

const httpAwsEs = require('http-aws-es');
const AWS = require('aws-sdk');
const elasticsearch = require('elasticsearch');
const config = require('./config');

let esClient;

// this is a getter of a singleton so we can manually assume the application role
// in integration tests before creating the client with AWS credentials
const getEsClient = () => {
	if (esClient) {
		return esClient;
	}

	if (!config.get('ES_HOST')) {
		throw new Error('ElasticSearch Index not defined');
	}

	if (!AWS.config.credentials) {
		throw new Error('AWS credentials not provided');
	}

	console.info(
		{ host: config.get('ES_HOST') },
		'Connecting to ElasticSearch host',
	);

	return new elasticsearch.Client({
		connectionClass: httpAwsEs,
		awsConfig: AWS.config,
		host: config.get('ES_HOST'),
		apiVersion: '6.3',
	});
};

function search(query) {
	console.info({ query }, 'Starting Elasticsearch');

	return getEsClient()
		.search({
			index: 'biz-ops-search',
			body: query,
		})
		.then(results => {
			console.info(
				{ hitCount: results.hits.total },
				'Elasticsearch complete with hits',
			);
			console.debug({ results }, 'Elasticsearch results');

			return {
				total: results.hits.total,
				results: results.hits ? results.hits.hits.map(hit => hit._source) : [],
			};
		})
		.catch(error => {
			if (error.response) {
				error.response = JSON.parse(error.response);
			}

			console.error(
				{ event: 'ELASTICSEARCH_ERROR', error, query },
				'Elasticsearch query failed',
			);

			throw error;
		});
}

module.exports = {
	search,
};

I wonder if it's related to this (or something like it) #2455

@srchase
Copy link
Contributor

srchase commented Jan 3, 2019

@wheresrhys

Yes, this is related to the credential resolution issue in 2.382.0.

It has been fixed and will be resolved with the next release of the SDK. For now, you'll need to use 2.381.0.

@srchase srchase added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jan 3, 2019
@srchase
Copy link
Contributor

srchase commented Jan 3, 2019

@wheresrhys

2.383.0 has been released. Closing out this issue.

@srchase srchase closed this as completed Jan 3, 2019
@lock
Copy link

lock bot commented Sep 26, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
closing-soon This issue will automatically close in 4 days unless further comments are made. guidance Question that needs advice or information.
Projects
None yet
Development

No branches or pull requests

2 participants