Skip to content

Instantly share code, notes, and snippets.

@justengland
Created January 19, 2017 21:38
Show Gist options
  • Save justengland/94d8b4d84f4652ee373d03c68bd13518 to your computer and use it in GitHub Desktop.
Save justengland/94d8b4d84f4652ee373d03c68bd13518 to your computer and use it in GitHub Desktop.
Add promises to AWS methids
const cloudformation = new AWS.CloudFormation();
const describeStacks = promisifyAWS(cloudformation, 'describeStacks');
// Issue with AWS Code structure.
// Not bening fixed, but this should work for the methods I have seen.
// https://github.com/aws/aws-sdk-js/issues/278
function promisifyAWS(service, method) {
return function(params) {
return new Promise(function (resolve, reject) {
service[method](params, function (err, data) {
if (err) {
reject(err);
return;
}
resolve(data);
});
});
}
}
@justengland
Copy link
Author

Not sure if this is the best code in the world, but it works and I can stop thinking about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment