Skip to content

Commit

Permalink
add system test and update package
Browse files Browse the repository at this point in the history
  • Loading branch information
Art Cuaresma authored and Art Cuaresma committed Jun 7, 2021
1 parent e0ebab6 commit e087792
Show file tree
Hide file tree
Showing 8 changed files with 36,928 additions and 6,961 deletions.
2 changes: 2 additions & 0 deletions aws-node-kinesis/handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as producer } from './kinesis/producer';
export { default as consumer } from './kinesis/consumer';
24 changes: 24 additions & 0 deletions aws-node-kinesis/kinesis/consumer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const { KinesisStreamHandler, KinesisStreamRecordPayload } = require("aws-sdk");

const consumer: KinesisSreamHandler = async (event) => {
try {
for (const record of event.Records) {
const payload: KinesisStreamRecordPayload = record.kinesis;
const message: string = Buffer.from(payload.data, 'base64').toString();

console.log(
`Kinesis Message:
partition key: ${payload.partitionKey}
sequence number: ${payload.sequenceNumber}
kinesis schema version: ${payload.kinesisSchemaVersion}
data: ${message}
`);

// Do something
}
} catch (error) {
console.log(error);
}
};

export default consumer;
47 changes: 47 additions & 0 deletions aws-node-kinesis/kinesis/producer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { APIGatewayProxyHandler } from 'aws-lambda';
import { Kinesis } from 'aws-sdk';
import { v4 as uuidv4 } from 'uuid';

const kinesis = new Kinesis({
apiVersion: '2013-12-02',
});

const producer: APIGatewayProxyHandler = async (event) => {
let statusCode: number = 200;
let message: string;

if (!event.body) {
return {
statusCode: 400,
body: JSON.stringify({
message: 'No body was found',
}),
};
}

const streamName: string = 'eventStream';

try {
await kinesis.putRecord({
StreamName: streamName,
PartitionKey: uuidv4(),
Data: event.body,
}).promise();

message = 'Message placed in the Event Stream!';

} catch (error) {
console.log(error);
message = error;
statusCode = 500;
}

return {
statusCode,
body: JSON.stringify({
message,
}),
};
};

export default producer;
Loading

0 comments on commit e087792

Please sign in to comment.