title: Kinesis lambda DynamoDB
body: <p>I am learning the AWS services for a use case. After going through the docs I came came up with the a simple flow. I want to ingest data into the Kinesis streams by using the Streams API and the KPL. I use the example putRecord method to ingest data to the streams. I am ingesting the this JSON to the stream - </p>
  
  <pre><code>{"userid":1234,"username":"jDoe","firstname":"John","lastname":"Doe"}
  </code></pre>
  
  <p>Once the data is ingested i get the following response in putRecordResult -</p>
  
  <pre><code>Put Result :{ShardId: shardId-000000000000,SequenceNumber: 49563097246355834103398973318638512162631666140828401666}
  Put Result :{ShardId: shardId-000000000000,SequenceNumber: 49563097246355834103398973318645765717549353915876638722}
  Put Result :{ShardId: shardId-000000000000,SequenceNumber: 49563097246355834103398973318649392495008197803400757250}
  </code></pre>
  
  <p>Now I write a Lambda function to get these data and push into a DynamoDB table. Here is my Lambda function -</p>
  
  <pre><code>console.log('Loading function');
  var AWS = require('aws-sdk');
  var tableName = "sampleTable";
  var doc = require('dynamodb-doc');
  var db = new doc.DynamoDB();
  
  exports.handler = (event, context, callback) =&gt; {
      //console.log('Received event:', JSON.stringify(event, null, 2));
      event.Records.forEach((record) =&gt; {
          // Kinesis data is base64 encoded so decode here
          const payload = new Buffer(record.kinesis.data, 'base64').toString('ascii');
          console.log('Decoded payload:', payload);
          var userid = event.userid;
          var username = event.username;
          var firstname = event.firstname;
          console.log(userid + "," + username +","+ firstname);
  
          var item = {
              "userid" : userid,
              "username" : username,
              "firstname" : firstname
          };
  
          var params = {
              TableName : tableName,
              Item : item
          };
          console.log(params);
  
          db.putItem(params, function(err, data){
              if(err) console.log(err);
              else console.log(data);
          });
  
      });
      callback(null, `Successfully processed ${event.Records.length} records.`);
  };
  </code></pre>
  
  <p>Somehow I am not able to see the console.logs in the lambda functions execution. I see in the streams page there have been putRecord to the stream and get as well but somehow i can see nothing in the Lambdafunction page nor in the DynamoDB table. </p>
  
  <p>I have an IAM policy for the Java code for the ingestion of the data into Kinesis, another for the Lambda function that is lambda-kinesis-execution-role and a policy for the DynamoDB to ingest data into the tables.</p>
  
  <p>Is there any tutorial that shows how it is done in the right way? I am getting a feeling that I am missing many points in this process for example how to link all those IAM policies and make them in sync so that when the data is put into the stream it is processed by Lambda and ends up in Dynamo?</p>
  
  <p>Any pointers and help is deeply appreciated.</p>