💻
Building and hosting a WebApp
  • Getting started
  • Project setup
    • Requirements
    • Files organisation
    • Lerna
    • Linter
    • Prettier
    • GitHook
    • Testing
    • Conclusion
  • Backend
    • Files organisation
    • Environment config
    • Express API
    • Security
    • Database
    • GraphQL
    • User authentication
    • Conclusion
  • Frontend
    • Create React App
    • Files organisation
    • Styles
    • Apollo Hooks
    • Form management
    • User authentication
    • Writing tests
    • Types generation
    • Conclusion
  • DevOps
    • CI/CD
    • AWS
      • Managing secrets
      • Pricing
      • RDS
      • S3
      • Route53
      • CloudFront
      • Serverless
      • Security
      • CloudFormation
    • Conclusion
  • 🚧Stripe payment
  • 🚧File upload
Powered by GitBook
On this page
  • Using Express with Serverless
  • Common problems

Was this helpful?

  1. DevOps
  2. AWS

Serverless

PreviousCloudFrontNextSecurity

Last updated 5 years ago

Was this helpful?

We are going to deploy the API using the . The is excellent and covers everything we need. If you are not familiar with Serverless, try the example and the .

In our setup, we will use 3 serverless plugins:

  • to transpile our code Javascript.

  • to run the app locally. (Note: add .build to .gitignore)

  • to read variables from our .env

  • to deploy the static files to S3.

Using Express with Serverless

We also need to change our index.ts file to use .

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.

Serverless Framework
documentation
hello work
user guide
Typescript
Offline
SSM
Finch
aws-serverless-express