@cumulus/aws-client
Version:
Utilities for working with AWS
42 lines • 1.79 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
const mem_1 = __importDefault(require("mem"));
const test_utils_1 = require("./test-utils");
const utils_1 = require("./utils");
const getRegion = () => process.env.AWS_DEFAULT_REGION || process.env.AWS_REGION || 'us-east-1';
const buildServiceClient = (Service, options) => {
if ((0, test_utils_1.inTestMode)()) {
return new Service((0, test_utils_1.getLocalstackAwsClientOptions)(Service, options));
}
return new Service(options);
};
const getMemoizedClient = (0, mem_1.default)(buildServiceClient, {
cacheKey: (arguments_) => `${(0, utils_1.getServiceIdentifer)(arguments_[0])}${JSON.stringify(arguments_[1])}`,
});
const getServiceClient = (Service, options = {}) => (overrides) => getMemoizedClient(Service, Object.assign(options, overrides));
/**
* Return a function which, when called, will return an AWS service object
*
* Note: The returned service objects are cached, so there will only be one
* instance of each service object per process.
*
* @param {AWSClientTypes} Service - an AWS service object constructor function
* @param {string} [version] - the API version to use
* @param {string} [serviceOptions] - additional options to pass to the service
* @returns {Function} a function which, when called, will return an instance of an AWS service
* object
* @private
*/
const awsClient = (Service, version, serviceOptions) => {
const options = {
region: getRegion(),
...serviceOptions,
};
if (version)
options.apiVersion = version;
return getServiceClient(Service, options);
};
module.exports = awsClient;
//# sourceMappingURL=client.js.map
;