Using async/await - Amazon SDK for JavaScript
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

The Amazon SDK for JavaScript v2 has reached end-of-support. We recommend that you migrate to Amazon 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 Amazon 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.