Categories
JavaScript Answers

How to use async and await with Node.js AWS SDK?

Spread the love

Sometimes, we want to use async and await with Node.js AWS SDK.

In this article, we’ll look at how to use async and await with Node.js AWS SDK.

How to use async and await with Node.js AWS SDK?

To use async and await with Node.js AWS SDK, we can call the promise method after we call the AWS SDK method.

For instance, we write

try {
  const key = await kms.generateDataKey().promise();
} catch (e) {
  console.log(e);
}

to call promise after call generateDataKey to return a promise with the resolved value assigned to key.

Conclusion

To use async and await with Node.js AWS SDK, we can call the promise method after we call the AWS SDK method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *