Skip to content

Commit 2db094f

Browse files
committed
Added function handler examples
Added summary and references
1 parent d2fb020 commit 2db094f

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

‎README.md‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,70 @@
44

55
[AWS Lambda@Edge](https://aws.amazon.com/lambda/edge) handler emulator (HTTP server).
66

7+
Provides a translation layer between [Node.js](https://nodejs.org) server and [Lambda](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-generating-http-responses.html) response format. The goal is simplify local testing without the need for complex dependencies.
8+
79
## Dependencies
810

911
- [Node.js](https://nodejs.org)
1012

13+
## Lambda function handlers
14+
15+
The following `origin-request/origin-response` format is currently supported.
16+
17+
### Synchronous example
18+
19+
```javascript
20+
/**
21+
* @see AWS::Serverless::Function
22+
*/
23+
exports.handler = function(event, context, callback) {
24+
const response = {
25+
status: '200',
26+
statusDescription: 'OK',
27+
headers: {
28+
'cache-control': [{
29+
key: 'Cache-Control',
30+
value: 'max-age=0'
31+
}],
32+
'content-type': [{
33+
key: 'Content-Type',
34+
value: 'text/html'
35+
}]
36+
},
37+
body: 'Success',
38+
};
39+
40+
callback(null, response);
41+
};
42+
```
43+
44+
### Asynchronous example
45+
46+
```javascript
47+
/**
48+
* @see AWS::Serverless::Function
49+
*/
50+
exports.handler = async function(event) {
51+
const response = {
52+
status: '200',
53+
statusDescription: 'OK',
54+
headers: {
55+
'cache-control': [{
56+
key: 'Cache-Control',
57+
value: 'max-age=0'
58+
}],
59+
'content-type': [{
60+
key: 'Content-Type',
61+
value: 'text/html'
62+
}]
63+
},
64+
body: 'Success',
65+
};
66+
67+
return response;
68+
};
69+
```
70+
1171
## Developers
1272

1373
### CLI options
@@ -27,6 +87,7 @@ Run [Mocha](https://mochajs.org) integration tests:
2787
## References
2888

2989
- [Example origin request](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-event-structure.html#example-origin-request)
90+
- [Example origin-response](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-event-structure.html#lambda-event-structure-response)
3091

3192
## Contributions
3293

0 commit comments

Comments
 (0)