Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
gatsby in aws lambda
const AWS = require("aws-sdk");
const {link} = require("linkfs");
const mock = require('mock-require');
const fs = require('fs');
const tmpDir = require('os').tmpdir();
exports.handler = (event, context) => {
const invokeGatsby = (context) => {
const gatsby = require("gatsby/dist/commands/build");
directory: __dirname,
//TODO replace with in-memory-fs ?!
const rewriteFs = () => {
// redirect paths
const linkedFs = link(fs, [
[`${__dirname}/.cache`, tmpDir+"/.cache"],
[`${__dirname}/public`, tmpDir+"/public"]
// those are missing in linkfs
linkedFs.ReadStream = fs.ReadStream;
linkedFs.WriteStream = fs.WriteStream;
// replace fs with linkfs globally
mock('fs', linkedFs);
Copy link

housser commented Sep 26, 2018

Do you have this idea as part of a functional project, or is it just a concept?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment