Skip to content

Commit

Permalink
update processors to optimize record handler instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinsgoodman committed Jan 15, 2023
1 parent c54d859 commit b33cd7b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { SQSHandler, SQSRecord } from 'aws-lambda';

const recordHandler = async (record: SQSRecord) => {
console.log(JSON.stringify(record.body));
};

export const handler: SQSHandler = async (event) => {
console.log('Example Job Processor Handler initiated');

const recordHandler = async (record: SQSRecord) => {
console.log(JSON.stringify(record.body));
};

// Ensuring we await on all the promises is super important to avoid
// accidentally killing the lambda prior to processing being completed.
await Promise.all(event.Records.map(recordHandler));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import type { DynamoDBStreamHandler, DynamoDBRecord } from 'aws-lambda';

const recordHandler = async (record: DynamoDBRecord) => {
if (record.eventName === 'INSERT' && record.dynamodb) {
console.log('Inserted Record', record.dynamodb.NewImage);
} else if (record.eventName === 'MODIFY' && record.dynamodb) {
console.log('Updated Record');
console.log('New Values', record.dynamodb.NewImage);
console.log('Old Values', record.dynamodb.OldImage);
} else if (record.eventName === 'REMOVE' && record.dynamodb) {
console.log('Removed Record', record.dynamodb.OldImage);
}
};

export const handler: DynamoDBStreamHandler = async (event) => {
console.log('Example Stream Processor Handler initiated');

const recordHandler = async (record: DynamoDBRecord) => {
if (record.eventName === 'INSERT' && record.dynamodb) {
console.log('Inserted Record', record.dynamodb.NewImage);
} else if (record.eventName === 'MODIFY' && record.dynamodb) {
console.log('Updated Record');
console.log('New Values', record.dynamodb.NewImage);
console.log('Old Values', record.dynamodb.OldImage);
} else if (record.eventName === 'REMOVE' && record.dynamodb) {
console.log('Removed Record', record.dynamodb.OldImage);
}
};

// Ensuring we await on all the promises is super important to avoid
// accidentally killing the lambda prior to processing being completed.
await Promise.all(event.Records.map(recordHandler));
Expand Down

0 comments on commit b33cd7b

Please sign in to comment.