diff --git a/src/discovery/index.js b/src/discovery/index.js index c6da36ec..43454c1e 100644 --- a/src/discovery/index.js +++ b/src/discovery/index.js @@ -1,4 +1,3 @@ -let { callbackify } = require('util') let { getAwsClient, useAWS } = require('../lib') /** @@ -43,18 +42,8 @@ module.exports = function lookup (callback) { if (err) callback(err) else { let Path = `/${stack || toLogicalID(`${app}-${env}`)}` - let GetParametersByPath = callbackify(client.ssm.GetParametersByPath) - GetParametersByPath({ Path, paginate: true }, function done (err, result) { - if (err && local && - err.message.includes('Inaccessible host') && - err.message.includes('localhost')) { - let msg = 'Sandbox internal services are unavailable, please ensure Sandbox is running' - callback(ReferenceError(msg)) - } - else if (err) { - callback(err) - } - else { + client.ssm.GetParametersByPath({ Path, paginate: true }) + .then(result => { let services = result.Parameters.reduce((a, b) => { let hierarchy = b.Name.split('/') hierarchy.shift() // leading slash @@ -74,8 +63,18 @@ module.exports = function lookup (callback) { return a }, {}) callback(null, services) - } - }) + }) + .catch(err => { + if (err && local && + err.message.includes('Inaccessible host') && + err.message.includes('localhost')) { + let msg = 'Sandbox internal services are unavailable, please ensure Sandbox is running' + callback(ReferenceError(msg)) + } + else { + callback(err) + } + }) } }) } diff --git a/src/lib/index.js b/src/lib/index.js index dd95ba15..fce14254 100644 --- a/src/lib/index.js +++ b/src/lib/index.js @@ -6,10 +6,10 @@ let isNode18 = Number(process.version.replace('v', '').split('.')[0]) >= 18 let nonLocalEnvs = [ 'staging', 'production' ] function getAwsClient (params, callback) { - let { callbackify } = require('util') - let _awsLite = require('@aws-lite/client') - let awsLite = callbackify(_awsLite) - awsLite(params, callback) + let awsLite = require('@aws-lite/client') + awsLite(params) + .then(client => callback(null, client)) + .catch(callback) } function useAWS () {