Skip to content

Commit

Permalink
express example
Browse files Browse the repository at this point in the history
  • Loading branch information
gojko committed Oct 4, 2016
1 parent affc135 commit 381c579
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -33,6 +33,7 @@
## Proxy API

* [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
* [Running Express Apps in AWS Lambda](express-app-lambda) – an example of how to deploy an existing Express app with minimal changes to Lambda

## Chat-bots

Expand Down
21 changes: 21 additions & 0 deletions express-app-lambda/README.md
@@ -0,0 +1,21 @@
# Running Express apps in AWS Lambda

This is a simple example that shows how to deploy an existing [Express](http://expressjs.com/) application, with minimal changes, to AWS Lambda.

## Running the example

1. run `npm install` to grab the dependencies
2. run `npm run generate-proxy` to create a simple proxy API for the express app
3. run `npm run deploy` to send everything up to AWS Lambda

The third step will print out a URL you can use to access the express app.

## Updating the app

1. Change [`app.js`](app.js)
2. (Optionally) use `npm install <PACKAGE NAME> -S` to install additional dependencies (always save them to `package.json` using `-S`)
3. Run `npm run update` to send the new version up to AWS. No need to generate the proxy again

## More information and limitations

See the [Running Express Apps in AWS Lambda](https://claudiajs.com/tutorials/serverless-express.html) tutorial.
11 changes: 11 additions & 0 deletions express-app-lambda/app.js
@@ -0,0 +1,11 @@
'use strict'
const express = require('express')
const app = express()

app.get('/', (req, res) => {
res.sendFile(`${__dirname}/index.html`)
})

// app.listen(3000) // <-- comment this line out from your app

module.exports = app // export your app so aws-serverless-express can use it
12 changes: 12 additions & 0 deletions express-app-lambda/index.html
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>Serverless Express Example</title>
</head>
<body>
<h1>Hello from Express</h1>
<p>this page is served by Express, through
<a href="https://www.npmjs.com/package/aws-serverless-express">aws-serverless-express</a> and
<a href="https://claudiajs.com/tutorials/deploying-proxy-api.html">Claudia.JS Proxy API</a></p>
</body>
</html>
19 changes: 19 additions & 0 deletions express-app-lambda/package.json
@@ -0,0 +1,19 @@
{
"name": "claudia-express",
"version": "1.0.0",
"description": "Example application for running a Node Express app on AWS Lambda using Amazon API Gateway.",
"main": "lambda.js",
"scripts": {
"deploy": "claudia create --handler lambda.handler --deploy-proxy-api --region us-east-1",
"update": "claudia update",
"generate-proxy": "claudia generate-serverless-express-proxy --express-module app"
},
"license": "Apache-2.0",
"dependencies": {
"aws-serverless-express": "^1.1.0",
"express": "^4.14.0"
},
"devDependencies": {
"claudia": "^2.1.0"
}
}

0 comments on commit 381c579

Please sign in to comment.