title: How to access Secret Manager in Cloud Function node.js10?
body: <p>I've been working on this for 2 days, very frustrated with the progress, any guidance on what is possibly wrong with my understanding/code/approach would be highly appreciated!</p>
  <p>I'm trying to get version value from secret mananger using node.js, the script below works fine on GCE, but whenever I run it on Cloud function it fails.</p>
  <pre><code>// My script on GCE, it works fine
  const { SecretManagerServiceClient } = require('@google-cloud/secret-manager');
  const secretManagerServiceClient = new SecretManagerServiceClient();
  const name = 'projects/moonhome/secrets/moonFirstSecret/versions/latest';
  
  testSecretManager = async () =&gt; {
    const [version] = await secretManagerServiceClient.accessSecretVersion({ name });
    const payload = version.payload.data.toString();
    console.debug(`Payload: ${payload}`);
  };
  testSecretManager();
  
  </code></pre>
  <pre><code>// My index.js on Cloud Function
  const { SecretManagerServiceClient } = require('@google-cloud/secret-manager');
  const secretManagerServiceClient = new SecretManagerServiceClient();
  const name = 'projects/moonhome/secrets/moonFirstSecret/versions/latest';
  
  testSecretManager = async () =&gt; {
    const [version] = await secretManagerServiceClient.accessSecretVersion({ name });
    const payload = version.payload.data.toString();
    console.debug(`Payload: ${payload}`);
  };
  
  exports.helloHttp = (req, res) =&gt; {
    testSecretManager();
    res.send(&quot;noooo1&quot;);
  };
  </code></pre>
  <pre><code>// One of many versions of packaga.json I tried on Cloud function
  {
    &quot;dependencies&quot;: {
        &quot;@google-cloud/secret-manager&quot;: {
          &quot;version&quot;: &quot;3.1.0&quot;,
          &quot;resolved&quot;: &quot;https://registry.npmjs.org/@google-cloud/secret-manager/-/secret-manager-3.1.0.tgz&quot;,
          &quot;integrity&quot;: &quot;sha512-/9IOWEhKAz/r3kSyp16kjudELkEJSRhwFfzukKbzQehVRZ3RceNDzjn+Rti1TivODJHEEIBZVsQFsKp7cLfUgQ==&quot;,
          &quot;requires&quot;: {
              &quot;google-gax&quot;: &quot;^2.1.0&quot;
        }
      }
    }
  }
  </code></pre>
  <p>Below are my questions:</p>
  <ol>
  <li><p>I noticed there is a <a href="https://cloud.google.com/functions/docs/reference/nodejs-system-packages#requesting_a_package" rel="nofollow noreferrer">list</a> of available system packages on node.js runtime in Cloud Function, so I am wondering if that's the reason. I already filed a request to add <code>@google-cloud/secret-manager</code> to node.js runtime. However, there is a example in the Cloud Function documentation where <code>escape-html</code> is used which also is absent from that list. My question is, <strong>should I request to add the secret-manager package to node.js runtime in my case?</strong></p>
  </li>
  <li><p>Since Cloud Function needs an event trigger, I also tried to wrap this <code>testSecretManager</code> with a simple function to handle http request and tested it at the endpoint in my browser. The simple function itself works fine, but whenever I insert anything related to secret manager into that function, either the function fails or the page shows it <code>Error: could not handle the request</code>. My question is, <strong>do I have to wrap <code>testSecretManager</code> with an HTTP request or any other event handling function to trigger my target function in Cloud Function?</strong></p>
  </li>
  <li><p>I am very confused with the <code>package.json</code> file on Cloud function, when I use secret-manager in GCE, the <code>package-lock.json</code> has 600+ lines, so I tried coping these lines to <code>package.json</code> on Cloud Function, but it does not work.....my question is, <strong>what should I include in package.json when all I want is just the <code>@google-cloud/secret-manager</code> package?</strong></p>
  </li>
  </ol>