Serverless

We are going to deploy the API using the Serverless Frameworkarrow-up-right. The documentationarrow-up-right is excellent and covers everything we need. If you are not familiar with Serverless, try the hello workarrow-up-right example and the user guidearrow-up-right.

In our setup, we will use 3 serverless plugins:

Using Express with Serverless

We also need to change our index.ts file to use aws-serverless-expressarrow-up-right.

exports.handler = (event: any, context: any) => {
  bootstrap().then(() => {
    const { app } = createApp();
    const server = awsServerlessExpress.createServer(app);
    awsServerlessExpress.proxy(server, event, context);
  });
}

Common problems

Error: Cannot find module './migrations'

Add import './migration.ts' to src/inddex.ts and create `migrations/index.ts`importing all migration files.

handler 'server' returned a promise and also uses a callback!

You can't use async with the main Serverless file. Use .then for the promises instead.

Last updated