Skip to content

Commit 381c579

Browse files
committed
express example
1 parent affc135 commit 381c579

File tree

5 files changed

+64
-0
lines changed

5 files changed

+64
-0
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
## Proxy API
3434

3535
* [Deploying a Proxy API](deploy-proxy-api) – an example of how to create an API Gateway that will proxy all requests directly to a Lambda function
36+
* [Running Express Apps in AWS Lambda](express-app-lambda) – an example of how to deploy an existing Express app with minimal changes to Lambda
3637

3738
## Chat-bots
3839

Diff for: express-app-lambda/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Running Express apps in AWS Lambda
2+
3+
This is a simple example that shows how to deploy an existing [Express](http://expressjs.com/) application, with minimal changes, to AWS Lambda.
4+
5+
## Running the example
6+
7+
1. run `npm install` to grab the dependencies
8+
2. run `npm run generate-proxy` to create a simple proxy API for the express app
9+
3. run `npm run deploy` to send everything up to AWS Lambda
10+
11+
The third step will print out a URL you can use to access the express app.
12+
13+
## Updating the app
14+
15+
1. Change [`app.js`](app.js)
16+
2. (Optionally) use `npm install <PACKAGE NAME> -S` to install additional dependencies (always save them to `package.json` using `-S`)
17+
3. Run `npm run update` to send the new version up to AWS. No need to generate the proxy again
18+
19+
## More information and limitations
20+
21+
See the [Running Express Apps in AWS Lambda](https://claudiajs.com/tutorials/serverless-express.html) tutorial.

Diff for: express-app-lambda/app.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict'
2+
const express = require('express')
3+
const app = express()
4+
5+
app.get('/', (req, res) => {
6+
res.sendFile(`${__dirname}/index.html`)
7+
})
8+
9+
// app.listen(3000) // <-- comment this line out from your app
10+
11+
module.exports = app // export your app so aws-serverless-express can use it

Diff for: express-app-lambda/index.html

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Serverless Express Example</title>
5+
</head>
6+
<body>
7+
<h1>Hello from Express</h1>
8+
<p>this page is served by Express, through
9+
<a href="https://www.npmjs.com/package/aws-serverless-express">aws-serverless-express</a> and
10+
<a href="https://claudiajs.com/tutorials/deploying-proxy-api.html">Claudia.JS Proxy API</a></p>
11+
</body>
12+
</html>

Diff for: express-app-lambda/package.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "claudia-express",
3+
"version": "1.0.0",
4+
"description": "Example application for running a Node Express app on AWS Lambda using Amazon API Gateway.",
5+
"main": "lambda.js",
6+
"scripts": {
7+
"deploy": "claudia create --handler lambda.handler --deploy-proxy-api --region us-east-1",
8+
"update": "claudia update",
9+
"generate-proxy": "claudia generate-serverless-express-proxy --express-module app"
10+
},
11+
"license": "Apache-2.0",
12+
"dependencies": {
13+
"aws-serverless-express": "^1.1.0",
14+
"express": "^4.14.0"
15+
},
16+
"devDependencies": {
17+
"claudia": "^2.1.0"
18+
}
19+
}

0 commit comments

Comments
 (0)