title: Gatsby preview server in a serverless/stateless environment
body: <p>Gatsby has <a href="https://www.gatsbyjs.com/docs/how-to/local-development/running-a-gatsby-preview-server/" rel="nofollow noreferrer">documentation on how to setup a preview server here</a></p>
  <p>Problem is it requires a server running 24/7 listening to requests, I would like to achieve the same result but in a serverless setup (AWS Lambda to be more specific) since we would need a preview very rarely.</p>
  <p>The context here is using Gatsby with Wordpress as a headless data backend, and I want to implement a custom preview link in Wordpress for previewing posts before publishing them.</p>
  <p>So far, there are two main setbacks :</p>
  <ol>
  <li>Size, currently the size of node_modules for a Gatsby starter with Wordpress is 570mb</li>
  <li>Speed, stateless means every preview request would be running <code>gatsby develop</code> again</li>
  </ol>
  <p>I honestly don't know a solution for size here, not sure how to strip down packages.</p>
  <p>As for speed, maybe there's a low level Gatsby API function to directly render a page to HTML? For example, a Node.js Lambda code could look like this (buildPageHTML is a hypothetical function I'm trying to find)</p>
  <pre class="lang-js prettyprint-override"><code>import buildPageHTML from &quot;gatsby&quot;
  
  exports.handler = async function(event) {
    const postID = event.queryStringParameters.postID
    return buildPageHTML(`/preview_post_by_id/${postID}`)
  }
  </code></pre>
  <p>Any ideas on how to go on about this?</p>