You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 8, 2024. It is now read-only.
and [S3 Events](https://docs.aws.amazon.com/AmazonS3/latest/dev/notification-content-structure.html).
8
+
A small library for [AWS Lambda](https://aws.amazon.com/lambda/details) providing routing for [API Gateway](https://aws.amazon.com/api-gateway), [Proxy Integrations](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-set-up-simple-proxy.html), [SNS](https://aws.amazon.com/sns) and [S3 Events](https://docs.aws.amazon.com/AmazonS3/latest/dev/notification-content-structure.html).
12
9
13
10
## Features
14
11
@@ -17,7 +14,11 @@ and [S3 Events](https://docs.aws.amazon.com/AmazonS3/latest/dev/notification-con
17
14
* Lambda Proxy Resource support for AWS API Gateway
18
15
* Enable CORS for requests
19
16
* No external dependencies
20
-
* Currently there are four `processors` (callers for Lambda) implemented: API Gateway ANY method (called proxyIntegration), SNS, SQS and S3.
17
+
* Currently there are four `processors` (callers for Lambda) implemented:
18
+
* API Gateway ANY method (called proxyIntegration)
19
+
* SNS
20
+
* SQS
21
+
* S3
21
22
22
23
## Installation
23
24
@@ -34,13 +35,12 @@ $ yarn add aws-lambda-router
34
35
35
36
## Getting Started
36
37
37
-
This is a simple example of `aws-lambda-router` in conjunction with ANY method and the API Gateway proxy integration. The following code will respond with a message when executed using an AWS API Gateway with a `GET` request on URL path `<base-url-of-gateway>/gateway-mapping/article/123`.
38
+
This is a simple example of `aws-lambda-router` in conjunction with ANY method and the API Gateway proxy integration. The following code will respond with a message when executed using an AWS API Gateway with a `GET` request on URL path `<base-url-of-gateway>/gateway-mapping/article/123`. The corresponding AWS API Gateway Resource is `/article/{articleId}`.
38
39
39
40
```js
40
-
import*asrouterfrom'aws-lambda-router'
41
+
import*asrouterfrom'aws-lambda-router'
41
42
42
43
exportconsthandler=router.handler({
43
-
// for handling an http-call from an AWS API Gateway proxyIntegration we provide the following config:
The proxy integration usually works using a path configured in the API gateway. For example: `/article/{id}`.
63
+
64
+
If you use the WIP *proxy path support*, the complete path will be used to match a route config in `proxyIntegration`. This can be used to build an [Simple Proxy with API Gateway]([https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-create-api-as-simple-proxy-for-http.html](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-create-api-as-simple-proxy-for-http.html))
65
+
66
+
Example:
67
+
* Resource in API Gateway : /{proxy+}
68
+
* Method: ANY
69
+
70
+
With the lambda configuration shown below the following paths are matched:
71
+
* _api-gateway-host_/article/list
72
+
* _api-gateway-host_/api/json/v1/schema
73
+
74
+
```js
75
+
constrouter=require('aws-lambda-router');
76
+
77
+
exports.handler=router.handler({
78
+
proxyIntegration: {
79
+
proxyPath: proxy
80
+
routes: [
81
+
{
82
+
path:'/article/list',
83
+
method:'GET',
84
+
action: (request, context) => {
85
+
return"You called me with: "+request.path;
86
+
}
87
+
},
88
+
{
89
+
path:'/api/json/v1/schema',
90
+
method:'GET',
91
+
action: (request, context) => {
92
+
return"You called me with: "+request.path;
93
+
}
94
+
}
95
+
]
96
+
}
97
+
}
98
+
```
60
99
61
100
## Enable CORS
62
101
@@ -66,7 +105,7 @@ See the following example:
66
105
67
106
68
107
```js
69
-
import*asrouterfrom'aws-lambda-router'
108
+
import*asrouterfrom'aws-lambda-router'
70
109
71
110
exportconsthandler=router.handler({
72
111
// for handling an http-call from an AWS Apigateway proxyIntegration we provide the following config:
@@ -91,10 +130,10 @@ If CORS is activated, these default headers will be sent on every response:
For handling calls in Lambdas initiated from AWS-SQS you can use the following code snippet:
157
196
158
197
```js
159
-
import*asrouterfrom'aws-lambda-router'
198
+
import*asrouterfrom'aws-lambda-router'
160
199
161
200
exportconsthandler=router.handler({
162
201
sqs: {
@@ -200,7 +239,7 @@ The action method will be called with the records of the [S3Event Structure](htt
200
239
The following examples demonstrates the most use cases:
201
240
202
241
```js
203
-
import*asrouterfrom'aws-lambda-router'
242
+
import*asrouterfrom'aws-lambda-router'
204
243
205
244
exportconsthandler=router.handler({
206
245
s3: {
@@ -290,16 +329,37 @@ See here: https://yarnpkg.com/en/docs/cli/link
290
329
291
330
## Release History
292
331
293
-
* 0.7.0 migrate to typescript; using aws-lambda typings; proxyIntegration: cors is now optional (default: false);
294
-
* 0.6.2 take away old gulp dependency to run tests, works now with scripts in package.json; normalize request path to start from local host (thanks to [@napicella](https://github.com/napicella))
295
-
* 0.6.1 s3: fix: aggregate result promises to one promise; fix: s3Route interface
296
-
* 0.6.0 new feature: S3 routes available.
297
-
* 0.5.0 new feature: SQS route integration now available; bugfix: SNS integration now works with Array of message instead of single message
298
-
* 0.4.0 now [the Context Object](https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html) pass through
299
-
* 0.3.1 proxyIntegration: avoid error if response object is not set; add some debug logging
300
-
* 0.3.0 proxyIntegration: add PATCH method; allow for custom status codes from route (thanks to [@mintuz](https://github.com/mintuz))
301
-
* 0.2.2 proxyIntegration: set correct header values now for CORS
302
-
* 0.2.1 proxyIntegration: CORS in Preflight, status code 400 for invalid body, set more CORS headers as default
303
-
* 0.2.0 Attention: breaking changes for configuration; add SNS event process
304
-
* 0.1.0 make it work now
305
-
* 0.0.1 initial release
332
+
* 0.7.0
333
+
* migrate to typescript
334
+
* using aws-lambda typings
335
+
* proxyIntegration: cors is now optional (default: false)
336
+
* experimental _proxy path support_ (thanks to [@swaner](https://github.com/swaner))
337
+
* 0.6.2
338
+
* take away old gulp dependency to run tests, works now with scripts in package.json
339
+
* normalize request path to start from local host (thanks to [@napicella](https://github.com/napicella))
340
+
* 0.6.1
341
+
* s3: fix: aggregate result promises to one promise;
342
+
* s3: s3Route interface
343
+
* 0.6.0
344
+
* new feature: S3 routes available.
345
+
* 0.5.0
346
+
* new feature: SQS route integration now available;
347
+
* bugfix: SNS integration now works with Array of message instead of single message
348
+
* 0.4.0
349
+
* now [the Context Object](https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html) pass through
350
+
* 0.3.1 proxyIntegration:
351
+
* avoid error if response object is not set;
352
+
* add some debug logging
353
+
* 0.3.0
354
+
* proxyIntegration: add PATCH method;
355
+
* allow for custom status codes from route (thanks to [@mintuz](https://github.com/mintuz))
356
+
* 0.2.2
357
+
* proxyIntegration: set correct header values now for CORS
358
+
* 0.2.1
359
+
* proxyIntegration: CORS in Preflight, status code 400 for invalid body, set more CORS headers as default
360
+
* 0.2.0 *Attention*: breaking changes for configuration;
0 commit comments