title: How can lambda be used to keep DynamoDB and Cloud Search in sync
body: <p>Assuming we're using AWS Triggers on DynamoDB Table, and that trigger is to run a lambda function, whose job is to update entry into CloudSearch (to keep DynamoDB and CS in sync).</p>
  
  <p>I'm not so clear on how Lambda would always keep the data in sync with the data in dynamoDB. Consider the following flow:</p>
  
  <ol>
  <li>Application updates a DynamoDB table's Record A (say to A1)</li>
  <li>Very closely after that Application updates same table's same record A (to A2)</li>
  <li>Trigger for 1 causes Lambda of 1 to start execute</li>
  <li>Trigger for 2 causes Lambda of 2 to start execute</li>
  <li>Step 4 completes first, so CloudSearch sees A2</li>
  <li>Now Step 3 completes, so CloudSearch sees A1</li>
  </ol>
  
  <p>Lambda triggers are not guaranteed to start ONLY after previous invocation is complete (Correct if wrong, and provide me link)</p>
  
  <p>As we can see, the thing goes out of sync.</p>
  
  <p>The closest I can think which will work is to use AWS Kinesis Streams, but those too with a single Shard (1MB ps limit ingestion). If that restriction works, then your consumer application can be written such that the record is first processed sequentially, i.e., only after previous record is put into CS, then the next record should be processed. Assuming the aforementioned statement is true, how to ensure the sync happens correctly, if there is so much of data ingestion into DynamoDB that more than one shards are needed n Kinesis?</p>