Skip to content

Instantly share code, notes, and snippets.

@rxgx
Last active March 18, 2026 16:31
Show Gist options
  • Select an option

  • Save rxgx/7e1b24de5936ff1b2b815a3d9cc3897a to your computer and use it in GitHub Desktop.

Select an option

Save rxgx/7e1b24de5936ff1b2b815a3d9cc3897a to your computer and use it in GitHub Desktop.

Revisions

  1. rxgx revised this gist May 4, 2018. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions asyncExample.js
    Original file line number Diff line number Diff line change
    @@ -8,6 +8,7 @@ function getAwsSecret(secretName) {
    }

    // Create a async function to use the Promise
    // Top level await is a proposal
    async function getAwsSecretAsync (secretName) {
    var error;
    var response = await getAwsSecret(secretName).catch(err => (error = err));
  2. rxgx created this gist May 4, 2018.
    29 changes: 29 additions & 0 deletions asyncExample.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    const AWS = require('aws-sdk');

    const client = new AWS.SecretsManager({});

    // Call the AWS API and return a Promise
    function getAwsSecret(secretName) {
    return client.getSecretValue({ SecretId: secretName }).promise();
    }

    // Create a async function to use the Promise
    async function getAwsSecretAsync (secretName) {
    var error;
    var response = await getAwsSecret(secretName).catch(err => (error = err));
    return [error, response];
    }

    // Call the async function and return NodeJS callback style
    module.exports = function asyncExample () {
    var [error, secret] = getAwsSecretAsync('dev/MySecret/MyService');

    if (error) {
    // Trigger an error and halt
    console.error(error);
    return;
    }

    // Use the result
    console.debug(secret);
    }