Created
June 13, 2020 22:03
-
-
Save jgcmarins/47c0577576f1078fbc4bcdbdf94a4dbd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { createServer, proxy } from 'aws-serverless-express'; | |
| import connectDatabase from './database'; | |
| import app from './app'; | |
| export const handler = (event, ctx) => { | |
| // This will re-use `cachedMongoConn` between function calls. | |
| // See https://www.mongodb.com/blog/post/serverless-development-with-nodejs-aws-lambda-mongodb-atlas | |
| // See https://docs.atlas.mongodb.com/best-practices-connecting-to-aws-lambda/ | |
| // https://mongoosejs.com/docs/lambda.html | |
| ctx.callbackWaitsForEmptyEventLoop = false; | |
| console.log('Connecting to database...'); | |
| connectDatabase() | |
| .then(() => proxy(createServer(app.callback()), event, ctx)) | |
| .catch(error => { | |
| console.error('Could not connect to database', { error }); | |
| throw error; | |
| }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment