title: Pass variables between different server-less functions
body: <p>I am building an application using the Twitter API and Netlify (aws lambda functions)
  This API requires these steps:</p>
  <ol>
  <li>When the user goes to my <code>/auth</code> function, a link to the Twitter authentication is created</li>
  <li>Once the user clicks that link, he is redirected to Twitter where a pop-up asks to allow my app to connect.</li>
  <li>Once the user approves, he is redirected to my <code>/auth</code> function again but this time the <code>authCode</code> is set to a number rather than being undefined. This <code>authCode</code> is used to instantiate the twitter client class and authorize it.</li>
  <li>A new instance of the Twitter client is created and authorized. This instance allows to query the tweets</li>
  </ol>
  <p>1, 2 and 3 works. However, the authorized instance only lives inside the <code>/auth</code> function. How can I pass it to different functions without losing its instantiation?</p>
  <p>How can I pass this instance to different server-less functions?</p>
  <p><code>client = new Client(OAuthClient)</code> this is what I want to pass around.</p>
  <p>I tried with a Middleware with little success. It seems the twitter client class gets re-instantiated (so without authorization) for every server-less function</p>
  <p><a href="https://playful-salmiakki-67d50e.netlify.app/.netlify/functions/auth" rel="nofollow noreferrer">https://playful-salmiakki-67d50e.netlify.app/.netlify/functions/auth</a></p>
  <pre><code>import Client from 'twitter-api-sdk';
  
  
  let client: Client;
  
  const auth = async (event, context, callback) =&gt; {
  
    const authCode = event.queryStringParameters ? event.queryStringParameters.code : undefined;
  
    const authUrl = OAuthClient.generateAuthURL({
      state: 'STATE',
      code_challenge: 'challenge',
    });
  
    console.log('HERE LINK:');
    console.log(authUrl);
  
    if (authCode) {
      await OAuthClient.requestAccessToken(authCode as string);
      client = new Client(OAuthClient); &lt;-- THIS IS WHAT I WANT TO PASS TO DIFFERENT FUNCTIONS
    }
    
    return {
      statusCode: 200,
      body: JSON.stringify({ message: 'Auth, go to the url displayed terminal'}),
      myClient: client
    };
  };
  
  exports.handler = middy().use(myMiddleware()).handler(auth);
  </code></pre>