How to use the aws-serverless-express.createServer function in aws-serverless-express

To help you get started, we’ve selected a few aws-serverless-express examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github geovanisouza92 / serverless-next / aws / api.js View on Github external
const middlewares = [
  middleware.eventContext(),
  /* get userId from event */ (req, res, next) => {
    try {
      req.userId = req.apiGateway.event.requestContext.authorizer.sub
    } catch (err) {
      req.userId = null
      console.warn(err.stack || err)
    }
    next()
  }
]

// Create a server for a API instance
const server = adapter.createServer(apiFactory(repo, middlewares))

module.exports.handler = (event, context, callback) => {
  // NOTE: aws-serverless-express uses context.succeed, but AWS already
  // deprecated it in favor of callback
  const fakeContext = {
    succeed: res => callback(null, res)
  }

  // Proxy the actual request
  adapter.proxy(server, event, fakeContext)
}
github MoveOnOrg / Spoke / lambda.js View on Github external
exports.handler = (event, context, callback) => {
  if (process.env.LAMBDA_DEBUG_LOG) {
    console.log('LAMBDA EVENT', event)
  }
  if (!event.command) {
    // default web server stuff
    const app = require('./build/server/server/index')
    const server = awsServerlessExpress.createServer(app.default)
    const startTime = (context.getRemainingTimeInMillis ? context.getRemainingTimeInMillis() : 0)
    const webResponse = awsServerlessExpress.proxy(server, event, context)
    if (process.env.DEBUG_SCALING) {
      const endTime = (context.getRemainingTimeInMillis ? context.getRemainingTimeInMillis() : 0)
      // confusingly, we do start - end, instead of the reverse,
      // because it's *remaining* time which counts down
      if ((startTime - endTime) > 3000) { //3 seconds
        console.log('SLOW_RESPONSE milliseconds:', startTime-endTime, event)
      }
    }
    return webResponse
  } else if (event.command === 'ping') {
    // no-op ping to keep server active, where useful, e.g. Amazon Lambda.
    callback()
  } else {
    // handle a custom command sent as an event
github nasa / cumulus / packages / api / app / index.js View on Github external
// default routes
app.use('/', router);

// global 404 response when page is not found
app.use((req, res) => {
  res.boom.notFound('requested page not found');
});

// catch all error handling
app.use((err, req, res, _next) => {
  res.error = JSON.stringify(err, Object.getOwnPropertyNames(err));
  return res.boom.badImplementation('Something broke!');
});

const server = awsServerlessExpress.createServer(app, null);

module.exports = {
  app,
  handler: (event, context) => awsServerlessExpress.proxy(server, event, context)
};
github phodal / mp / handler.js View on Github external
const awsServerlessExpress = require('aws-serverless-express');
const app = require('./index');
const server = awsServerlessExpress.createServer(app);

exports.runserver = (event, context) => {
   console.log("EVENT: " + JSON.stringify(event));
   awsServerlessExpress.proxy(server, event, context)
}
github prisma-archive / graphcool-templates / outdated / auth / auth0-authentication / functions / aws-lambda / handler.js View on Github external
'use strict';

const awsServerlessExpress = require('aws-serverless-express')
const app = require('./app')

const server = awsServerlessExpress.createServer(app)

module.exports.auth0Authentication = (event, context) => awsServerlessExpress.proxy(server, event, context);
github prisma-archive / graphcool-templates / outdated / auth / auth0-database-authentication / functions / aws-lambda / handler.js View on Github external
'use strict';

const awsServerlessExpress = require('aws-serverless-express')
const app = require('./app')

const server = awsServerlessExpress.createServer(app)

module.exports.auth0Authentication = (event, context) => awsServerlessExpress.proxy(server, event, context);
github lambdasync / lambdasync / bin / template / new / express / index.js View on Github external
'use strict';
const awsServerlessExpress = require('aws-serverless-express');
const app = require('./src/app');

const server = awsServerlessExpress.createServer(app);

exports.handler = (event, context) => awsServerlessExpress.proxy(server, event, context);
github tonyfromundefined / next-starter / serverless / main.ts View on Github external
'text/xml',
]

const app = asyncify(express())

app.use(nocache())
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.use(cookieParser())

app.use(api)

app.get('/', (index as any).render)
app.get('/_error', (error as any).render)

const server = awsServerlessExpress.createServer(app, undefined, BINARY_MIME_TYPES)

export const handler = (event: any, context: Context) => {
  return awsServerlessExpress.proxy(server, event, context)
}
github rdlabo / serverless-nestjs / src / index.ts View on Github external
    .then(() => serverless.createServer(expressApp));
}
github dhruv-kumar-jha / aws-lambda-graphql / lambda.js View on Github external
'use strict'

const awsServerlessExpress = require('aws-serverless-express');
const app = require('./src/app');
const server = awsServerlessExpress.createServer(app);

exports.handler = (event, context) => awsServerlessExpress.proxy(server, event, context);

aws-serverless-express

This library enables you to utilize AWS Lambda and Amazon API Gateway to respond to web and API requests using your existing Node.js application framework.

Apache-2.0
Latest version published 4 years ago

Package Health Score

74 / 100
Full package analysis