AWS | Typescript Kinesis Example

Produce and Consume data on a Kinesis Data Stream with Typescript.

Clone This Example

Step #1 - npm install serverless -g
Step #2 - serverless install -u https://github.com/serverless/examples/tree/master/aws-node-typescript-kinesis -n  aws-node-typescript-kinesis

Simple Kinesis Example

This example demonstrates how to setup a Kinesis producer and consumer to send and receive messages through a Kinesis Data Stream.

Use Cases

  • Decouple message producers from message consumers.
  • This is one way to architect for scale and reliability.
  • Real-time processing of streaming data

Setup

  • sls deploy

Usage

  • To send a message to the producer, get the address from your sls deploy output.
Serverless: Stack update finished...
Service Information
service: aws-node-typescript-kinesis
stage: dev
region: us-east-1
stack: aws-node-typescript-kinesis-dev
resources: 16
api keys:
  None
endpoints:
  POST - https://xxx.execute-api.us-east-1.amazonaws.com/dev/producer
functions:
  producer: aws-node-typescript-kinesis-dev-producer
  consumer: aws-node-typescript-kinesis-dev-consumer
layers:
  None
  • To print out the logs of the Kinesis consumer handler on the terminal sls logs -f consumer -t

  • send a HTTP POST request to the producer lambda

curl -d "{ 'key': 'employee', 'value': 'Bill' }" \
https://xxx.execute-api.us-east-1.amazonaws.com/dev/producer
  • You should see confirmation that the message was sent. {"message":"Message placed in the Event Stream!"}

  • The logs from the consumer will be delayed several seconds.

INFO    Kinesis Message:
          partition key: eb2da7494bd7-8ccce1decce95d
          sequence number: 49608726715828497972227004620876254203171519877947064322
          kinesis schema version: 1.0
          data: { 'key': 'employee', 'value': 'Bill' }

Acknowledgements

Adapted from Miguel Frazao's SQS Standard example.

view on Github

Latest commit b2f54ec on Sep 24, 2017

New to serverless?

To get started, pop open your terminal & run:

npm install serverless -g