Skip to content

Commit 64d832f

Browse files
author
Christian Gohlke
committed
add api gateway example; prepare release 0.8.3
1 parent b27d3a7 commit 64d832f

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ exports.handler = router.handler({
109109
```
110110

111111
Typescript example:
112+
112113
```ts
113114
import * as router from 'aws-lambda-router'
114115
import { ProxyIntegrationEvent } from 'aws-lambda-router/lib/proxyIntegration'
@@ -145,6 +146,9 @@ To activate CORS on all http methods (OPTIONS requests are handled automatically
145146
See the following example:
146147
147148
149+
<details>
150+
<summary>CORS example</summary>
151+
148152
```js
149153
import * as router from 'aws-lambda-router'
150154

@@ -164,6 +168,8 @@ export const handler = router.handler({
164168
})
165169
```
166170
171+
</details>
172+
167173
If CORS is activated, these default headers will be sent on every response:
168174
169175
"Access-Control-Allow-Origin" = "'*'"
@@ -214,6 +220,9 @@ SNS Event Structure: https://docs.aws.amazon.com/sns/latest/dg/sns-message-and-j
214220
215221
For handling calls in Lambdas initiated from AWS-SNS you can use the following code snippet:
216222
223+
<details>
224+
<summary>SNS to Lambda example</summary>
225+
217226
```js
218227
import * as router from 'aws-lambda-router'
219228

@@ -231,12 +240,17 @@ export const handler = router.handler({
231240
})
232241
```
233242
243+
</details>
244+
234245
The *records* parameter contains `SNSEventRecord[]`. An exampe event structure can be found [here](lib/event-examples/sns.json). For example you can parse now the [message attributes of the SNS](https://docs.aws.amazon.com/sns/latest/dg/sns-message-attributes.html) or reads the topic arn of SNS.
235246
236247
## SQS to Lambda Integrations
237248
238249
For handling calls in Lambdas initiated from AWS-SQS you can use the following code snippet:
239250
251+
<details>
252+
<summary>SQS to Lambda example</summary>
253+
240254
```js
241255
import * as router from 'aws-lambda-router'
242256

@@ -260,6 +274,8 @@ export const handler = router.handler({
260274
})
261275
```
262276
277+
</details>
278+
263279
An SQS message always contains an array of records. In each SQS record there is the message in the body JSON key.
264280
The `action` method gets all body elements from the router as an array.
265281
@@ -283,6 +299,9 @@ The action method will be called with the records of the [S3Event Structure](htt
283299
284300
The following examples demonstrates the most use cases:
285301
302+
<details>
303+
<summary>S3 to Lambda example</summary>
304+
286305
```js
287306
import * as router from 'aws-lambda-router'
288307

@@ -338,6 +357,7 @@ export const handler = router.handler({
338357
}
339358
})
340359
```
360+
</details>
341361
342362
Per s3 event there can be several records per event. The action methods are called one after the other record. The result of the action method is an array with objects insides.
343363
@@ -347,6 +367,9 @@ Per default a status code 200 will be returned. This behavior can be overridden.
347367
348368
By providing a body property in the returned object you can modify the status code and response headers.
349369
370+
<details>
371+
<summary>Response example</summary>
372+
350373
```js
351374
return {
352375
// Allow for custom status codes depending on execution.
@@ -365,6 +388,9 @@ return {
365388
}
366389
```
367390
391+
</details>
392+
393+
368394
## Local developement
369395
370396
The best is to work with ```yarn link```
@@ -380,7 +406,7 @@ Increase version in **package.json** (using [semantic version syntax](https://se
380406
Thats all.
381407
382408
## Release History
383-
* unreleased
409+
* 0.8.3
384410
* added records to the SQS (#43) and SNS (#44) action for further processing
385411
* 0.8.2
386412
* added support for Open API parameter definitions e.g.: /section/{id}

0 commit comments

Comments
 (0)