├── .gitignore ├── diagram ├── create_zip.png ├── invoke-url.png ├── architecture.png ├── create_method.png └── create_resource.png ├── sample_code ├── lambda.js ├── package.json ├── app.js └── index.html ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md └── CONTRIBUTING.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | build 3 | npm-debug.log 4 | .env 5 | .gitignore 6 | .DS_Store 7 | -------------------------------------------------------------------------------- /diagram/create_zip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/aws-lambda-demo-with-node-express/HEAD/diagram/create_zip.png -------------------------------------------------------------------------------- /diagram/invoke-url.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/aws-lambda-demo-with-node-express/HEAD/diagram/invoke-url.png -------------------------------------------------------------------------------- /diagram/architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/aws-lambda-demo-with-node-express/HEAD/diagram/architecture.png -------------------------------------------------------------------------------- /diagram/create_method.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/aws-lambda-demo-with-node-express/HEAD/diagram/create_method.png -------------------------------------------------------------------------------- /diagram/create_resource.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/aws-lambda-demo-with-node-express/HEAD/diagram/create_resource.png -------------------------------------------------------------------------------- /sample_code/lambda.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | const awsServerlessExpress = require("aws-serverless-express") 3 | const app = require("./app") 4 | const server = awsServerlessExpress.createServer(app) 5 | 6 | exports.handler = (event, context) => { 7 | awsServerlessExpress.proxy(server, event, context); 8 | }; 9 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 4 | opensource-codeofconduct@amazon.com with any additional questions or comments. 5 | -------------------------------------------------------------------------------- /sample_code/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "simple-calculator", 3 | "version": "1.0.0", 4 | "description": "Sample Node-Express app running on AWS Lambda", 5 | "main": "calculator.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "buraku", 10 | "license": "MIT-O", 11 | "dependencies": { 12 | "aws-serverless-express": "^3.3.8", 13 | "express": "^4.17.1" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | the Software, and to permit persons to whom the Software is furnished to do so. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 10 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 11 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 12 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 13 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 14 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 15 | 16 | -------------------------------------------------------------------------------- /sample_code/app.js: -------------------------------------------------------------------------------- 1 | // jshint esversion: 6 2 | 3 | const express = require("express"); 4 | var bodyParser = require("body-parser"); 5 | const app = express(); 6 | const port =3000 7 | app.use( 8 | bodyParser.urlencoded({ 9 | extended: true, 10 | }) 11 | ); 12 | 13 | app.get("/", function (req, res) { 14 | res.sendFile(__dirname + "/index.html"); 15 | }); 16 | 17 | app.post("/", function (req, res) { 18 | let num1 = Number(req.body.num1); 19 | let num2 = Number(req.body["num2"]); 20 | let operator = ""; 21 | switch (req.body.operator) { 22 | case "+": 23 | operator = add; 24 | break; 25 | case "x": 26 | operator = multiply; 27 | break; 28 | case "-": 29 | operator = subtract; 30 | break; 31 | case "/": 32 | operator = divide; 33 | break; 34 | } 35 | console.log(calculator(num1, num2, operator)); 36 | res.send(` 37 |
41 | 42 | There's no need for compliments
43 |I already know i'm the smartest app in the world hahaha ;)
44 |45 | By the way I'm running on a Lambda Function 46 |
47 | 48 | ` ); 49 | }); 50 | 51 | 52 | function add(num1, num2) { 53 | return num1 + num2; 54 | } 55 | 56 | function subtract(num1, num2) { 57 | return num1 - num2; 58 | } 59 | 60 | function multiply(num1, num2) { 61 | return num1 * num2; 62 | } 63 | function divide(num1, num2) { 64 | return num1 / num2; 65 | } 66 | function calculator(num1, num2, operator) { 67 | return operator(num1, num2); 68 | } 69 | 70 | app.listen(port, () => console.log(`calculator listening on port {port}!`)) 71 | 72 | module.exports = app 73 | -------------------------------------------------------------------------------- /sample_code/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # How to Deploy a Node-Express App on AWS Lambda
2 |
3 | The purpose of this repository is to demonstrate how to deploy a simple web
4 | application built by Express - Node.js web application framework on AWS Lambda.
5 |
6 |
7 | ### Requirements
8 | - `Node.js with Node Package Manager(npm)` should be installed on your local system.
9 |
10 |
11 | ### Architecture
12 |
13 | **Request Response Cycle :**
14 |
15 |
16 |
17 |
32 |
33 |
52 |
53 |
59 |
60 |