8000 Support AWS Lambda as target serverless · Issue #6173 · vercel/next.js · GitHub
[go: up one dir, main page]

Skip to content
Support AWS Lambda as target serverless #6173
@iam4x

Description

@iam4x

Hey 👋

Thank you a lot @timneutkens for great #5927 PR, amazing work 🥇

I was going through the code of your PR in order to make it work with AWS Lambda and it was pretty straightforward.

I had to "hack" your next-serverless-loader.ts function in order to be able to inject serverless-http module that way:

// next.config.js

const nextServerlessLoader = require("next/dist/build/webpack/loaders/next-serverless-loader");
const { stripIndent } = require("common-tags");

const originalLoader = Object.assign(
  {},
  { default: nextServerlessLoader.default }
);
nextServerlessLoader.default = function() {
  const transformed = originalLoader.default
    .call(this)
    .replace(`export async function render`, `async function nextRender`);


  const result = stripIndent`
    import serverlessHttp from 'serverless-http';${transformed}
    export const render = serverlessHttp(nextRender);
  `;

  return result;
};

module.exports = {
  target: "serverless"
}

This is working great, the output can be directly plugged to an handler 🏆

functions:
  index:
    handler: .next/serverless/pages/index.render
    events:
      - http: GET /

Here are my questions:

  • Are you willing to support other platforms than now.sh?
  • If yes could we expose an option to auto-import the serverless-http module?
  • If not, should I write a custom plugin to nextjs?

Cheers ✌️

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0