Skip to content

Commit 337a6ec

Browse files
committed
docs: updated docs.
1 parent ecf8d96 commit 337a6ec

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

README.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,46 @@
1-
# aws-lambda-express-restapi
1+
# AWS Lambda REST API using Serverless, Express and Nodejs
2+
3+
Demostrate how to use the popular Node web framework Express.js to deploy a Serverless REST API. This means you can use your existing code + the vast Express.js ecosystem and benefits of Serverless.
4+
5+
## Getting Started
6+
7+
We'll install the `serverless-http` framework
8+
9+
```sh
10+
$ npm install --save express serverless-http
11+
```
12+
13+
The `serverless-http` package is a handy piece of middleware that handles the interface between your Node.js application and the specifics of API Gateway.
14+
15+
Let's create an index.js file that has our application code:
16+
17+
```js
18+
// index.js
19+
20+
const serverless = require('serverless-http');
21+
const express = require('express')
22+
const app = express()
23+
24+
app.get('/', function (req, res) {
25+
res.send('Hello World!')
26+
})
27+
28+
module.exports.handler = serverless(app);
29+
```
30+
31+
To get this application deployed, let's create a `serverless.yml` in our working directory:
32+
33+
```yml
34+
# serverless.yml
35+
36+
functions:
37+
app:
38+
handler: index.handler
39+
events:
40+
- http: ANY /
41+
- http: 'ANY {proxy+}'
42+
```
43+
44+
This is a pretty basic configuration. We've created one function, app, which uses the exported handler from our index.js file. Finally, it's configured with some HTTP triggers.
45+
46+
We've used a very broad path matching so that all requests on this domain are routed to this function. All of the HTTP routing logic will be done inside the Express application.

0 commit comments

Comments
 (0)