lib/cf-resources/api-gateway-resource/index.js
function replaceVariables(localPath, variables) {
    return new Promise(function(resolve, reject) {
        // Read the file
        let body = fs.readFileSync(localPath, 'utf8');

        // Do the replacement for all of the variables
        const keys = Object.keys(variables);
        keys.forEach(function(key) {
            const value = variables[key];
            const re = new RegExp(`"\\$${key}"`, 'g');

            // Parse the value (to see if it is falsey)
            try {
                const parsed = JSON.parse(value);
                body = body.replace(re, parsed ? `"${parsed}"` : `null`);
            } catch (err) {
                // Not valid JSON, treat it as a string
                body = body.replace(re, `"${value}"`);
            }
        });

        console.log('Variables replaced', body);
        fs.writeFile(localPath, body, function(err) {
            if (err) return reject(err);
            resolve(localPath);
        });
    });
}
function replaceVariables(localPath, variables) {
    return new Promise(function(resolve, reject) {
        // Read the file
        let body = fs.readFileSync(localPath, 'utf8');

        // Do the replacement for all of the variables
        const keys = Object.keys(variables);
        keys.forEach(function(key) {
            const value = variables[key];
            const re = new RegExp(`"\\$${key}"`, 'g');

            // Parse the value (to see if it is falsey)
            try {
                const parsed = JSON.parse(value);
                body = body.replace(re, parsed ? `"${parsed}"` : `null`);
            } catch (err) {
                // Not valid JSON, treat it as a string
                body = body.replace(re, `"${value}"`);
            }
        });

        console.log('Variables replaced', body);
        fs.writeFile(localPath, body, function(err) {
            if (err) return reject(err);
            resolve(localPath);
        });
    });
}
function replaceVariables ( localPath , variables ) { return new Promise ( function ( resolve , reject ) { // Read the file let body = fs . readFileSync ( localPath , 'utf8' ) ; // Do the replacement for all of the variables const keys = Object . keys ( variables ) ; keys . forEach ( function ( key ) { const value = variables [ key ] ; const re = new RegExp ( ` \\ ${ key } ` , 'g' ) ; // Parse the value (to see if it is falsey) try { const parsed = JSON . parse ( value ) ; body = body . replace ( re , parsed ? ` ${ parsed } ` : ` ` ) ; } catch ( err ) { // Not valid JSON, treat it as a string body = body . replace ( re , ` ${ value } ` ) ; } } ) ; console . log ( 'Variables replaced' , body ) ; fs . writeFile ( localPath , body , function ( err ) { if ( err ) return reject ( err ) ; resolve ( localPath ) ; } ) ; } ) ; }
Helper function for replacing variables in the API definition

@returns {Promise} which resolves into the same localPath the file was
written back to
Helper function for replacing variables in the API definition