Using async/await - AWS SDK for JavaScript

The AWS SDK for JavaScript v2 has reached end-of-support. We recommend that you migrate to AWS SDK for JavaScript v3. For additional details and information on how to migrate, please refer to this announcement.

Using async/await

You can use the async/await pattern in your calls to the AWS SDK for JavaScript. Most functions that take a callback do not return a promise. Since you only use await functions that return a promise, to use the async/await pattern you need to chain the .promise() method to the end of your call, and remove the callback.

The following example uses async/await to list all of your Amazon DynamoDB tables in us-west-2.

var AWS = require("aws-sdk"); //Create an Amazon DynamoDB client service object. dbClient = new AWS.DynamoDB({ region: "us-west-2" }); // Call DynamoDB to list existing tables const run = async () => { try { const results = await dbClient.listTables({}).promise(); console.log(results.TableNames.join("\n")); } catch (err) { console.error(err); } }; run();
Note

Not all browsers support async/await. See Async functions for a list of browsers with async/await support.