Skip to content

Commit b27d3a7

Browse files
authored
added records to the SNS action (spring-media#44)
added records to the SNS action for further usage
1 parent 6e3590e commit b27d3a7

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,15 @@ export const handler = router.handler({
224224
// a regex to match the content of the SNS-Subject:
225225
subject: /.*/,
226226
// Attention: the message is JSON-stringified
227-
action: (sns, context) => service.doSomething(JSON.parse(sns.Message))
227+
action: (sns, context, records) => service.doSomething(JSON.parse(sns.Message))
228228
}
229229
]
230230
}
231231
})
232232
```
233233
234+
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.
235+
234236
## SQS to Lambda Integrations
235237
236238
For handling calls in Lambdas initiated from AWS-SQS you can use the following code snippet:
@@ -378,15 +380,14 @@ Increase version in **package.json** (using [semantic version syntax](https://se
378380
Thats all.
379381
380382
## Release History
381-
* 0.8.3
382-
* added records to the SQS action for further processing
383+
* unreleased
384+
* added records to the SQS (#43) and SNS (#44) action for further processing
383385
* 0.8.2
384386
* added support for Open API parameter definitions e.g.: /section/{id}
385387
* 0.8.1
386388
* fix: changed ProxyIntegrationEvent body type to be generic but defaults to unknown
387389
* fix: changed @types/aws-lambda from devDependency to dependency
388390
* **breaking**: error response objects (thrown or rejected) now need to set `statusCode` instead of `status` (consistent with response)
389-
390391
* 0.7.1
391392
* code style cleanup
392393
* fix: hosted package on npmjs should now worked

lib/sns.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { Context, SNSEvent, SNSMessage } from 'aws-lambda'
1+
import { Context, SNSEvent, SNSMessage, SNSEventRecord } from 'aws-lambda'
22
import { ProcessMethod } from './EventProcessor'
33

44
export type SnsEvent = SNSEvent
55

66
export interface SnsRoute {
77
subject: RegExp
8-
action: (sns: SNSMessage, context: Context) => Promise<any> | any
8+
action: (sns: SNSMessage, context: Context, records: SNSEventRecord[]) => Promise<any> | any
99
}
1010

1111
export interface SnsConfig {
@@ -29,7 +29,7 @@ export const process: ProcessMethod<SnsConfig, SnsEvent, Context, any> = (snsCon
2929
for (const routeConfig of snsConfig.routes) {
3030
if (routeConfig.subject instanceof RegExp) {
3131
if (routeConfig.subject.test(sns.Subject)) {
32-
const result = routeConfig.action(sns, context)
32+
const result = routeConfig.action(sns, context, event.Records)
3333
return result || {}
3434
}
3535
} else {

test/sns.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { process as sns, SnsConfig, SnsEvent } from '../lib/sns'
33
describe('sns.processor', () => {
44
const context = {} as any
55

6-
it('context should be pass through', () => {
6+
it('context and records should be pass through', () => {
77
const actionSpy = jasmine.createSpy('action')
88

99
const context = { bla: 'blup' } as any
@@ -12,7 +12,7 @@ describe('sns.processor', () => {
1212

1313
sns(snsCfg, event, context)
1414

15-
expect(actionSpy).toHaveBeenCalledWith(event.Records[0].Sns, context)
15+
expect(actionSpy).toHaveBeenCalledWith(event.Records[0].Sns, context, event.Records)
1616
})
1717

1818
it('should ignore event if it is no SNS event', () => {

0 commit comments

Comments
 (0)