|
1 | 1 | import type { DynamoDBStreamHandler, DynamoDBRecord } from 'aws-lambda'; |
2 | 2 |
|
| 3 | +const recordHandler = async (record: DynamoDBRecord) => { |
| 4 | + if (record.eventName === 'INSERT' && record.dynamodb) { |
| 5 | + console.log('Inserted Record', record.dynamodb.NewImage); |
| 6 | + } else if (record.eventName === 'MODIFY' && record.dynamodb) { |
| 7 | + console.log('Updated Record'); |
| 8 | + console.log('New Values', record.dynamodb.NewImage); |
| 9 | + console.log('Old Values', record.dynamodb.OldImage); |
| 10 | + } else if (record.eventName === 'REMOVE' && record.dynamodb) { |
| 11 | + console.log('Removed Record', record.dynamodb.OldImage); |
| 12 | + } |
| 13 | +}; |
| 14 | + |
3 | 15 | export const handler: DynamoDBStreamHandler = async (event) => { |
4 | 16 | console.log('Example Stream Processor Handler initiated'); |
5 | 17 |
|
6 | | - const recordHandler = async (record: DynamoDBRecord) => { |
7 | | - if (record.eventName === 'INSERT' && record.dynamodb) { |
8 | | - console.log('Inserted Record', record.dynamodb.NewImage); |
9 | | - } else if (record.eventName === 'MODIFY' && record.dynamodb) { |
10 | | - console.log('Updated Record'); |
11 | | - console.log('New Values', record.dynamodb.NewImage); |
12 | | - console.log('Old Values', record.dynamodb.OldImage); |
13 | | - } else if (record.eventName === 'REMOVE' && record.dynamodb) { |
14 | | - console.log('Removed Record', record.dynamodb.OldImage); |
15 | | - } |
16 | | - }; |
17 | | - |
18 | 18 | // Ensuring we await on all the promises is super important to avoid |
19 | 19 | // accidentally killing the lambda prior to processing being completed. |
20 | 20 | await Promise.all(event.Records.map(recordHandler)); |
|
0 commit comments