Skip to content

Instantly share code, notes, and snippets.

@kuc-arc-f
Created January 16, 2022 03:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuc-arc-f/1711f842de99c93938324307cf5ebde1 to your computer and use it in GitHub Desktop.
Save kuc-arc-f/1711f842de99c93938324307cf5ebde1 to your computer and use it in GitHub Desktop.
Serverless Framework + express, deploy sample
const serverless = require('serverless-http');
const express = require('express');
const indexRouter = require('./routes/index');
const usersRouter = require('./routes/users');
const app = express();
app.use('/', indexRouter);
app.use('/users',usersRouter);
//module.exports = app;
module.exports.handler = serverless(app);
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/', function(req, res, next) {
console.log("root");
res.json({ret: 'root OK'});
});
router.get('/test', function(req, res, next) {
console.log("test");
res.json({ret: 'OK'});
});
router.get('/test2', function(req, res, next) {
console.log("test");
res.json({ret: 'OK, test2'});
});
module.exports = router;
{
"name": "sls-express1",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www",
"dev": "nodemon ./bin/www"
},
"dependencies": {
"aws-sdk": "^2.1058.0",
"cookie-parser": "~1.4.4",
"debug": "~2.6.9",
"express": "~4.16.1",
"hbs": "~4.0.4",
"http-errors": "~1.6.3",
"morgan": "~1.9.1",
"nodemon": "^2.0.15",
"serverless-http": "^2.7.0"
}
}
service: sls-express1
# app and org for use with dashboard.serverless.com
frameworkVersion: "2"
provider:
name: aws
runtime: nodejs14.x
region: ap-northeast-1
stage: dev
lambdaHashingVersion: 20201221
functions:
hello:
handler: app.handler
events:
- http:
path: /
method: ANY
- http:
path: /test
method: ANY
- http:
path: /test2
method: ANY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment