title: Only call Lambda function when Aurora transaction commits, but guarantee call (ACID)
body: <p>For a micro service in new project I am currently considering whether to use DynamoDB or Aurora MySQL as the underlying data store. The micro service offers a REST API to a user interface, and there will be several other micro services. Those other micro services are supposed to listen to an event stream (event sourcing) generated by the UI-connected service to keep additional read models in sync.</p>
  
  <p>I am trying to figure out a way to guarantee that the events published to the change event stream exactly match the changes to the data in the underlying data store.  Generally, the concern is that if the REST API handler e.g. is interrupted half-way through its execution, it may have changed the data but not created the event yet (assuming that the change event is published after the data change). I am now looking for mechanisms that will alleviate this concern. </p>
  
  <p>For DynamoDB there are DynamoDB streams and AWS Lambda Triggers to react to data changes at data store level. The triggered Lambda could transformation the low-level data change into a meaningful change event and then publish the event to SNS, SQS or Kinesis.</p>
  
  <p>For Aurora MySQL I have yet to come up with such a mechanism. I have seen articles that describe two mechanisms:</p>
  
  <ol>
  <li>Enable the binary log for Aurora and use an additional EC2 instance to process the change stream. Publish events for other services from this stream.</li>
  <li>Use the native lambda_sync or lambda_async function to call a Lambda from MySQL triggers. Publish events for other services from within this Lambda.</li>
  </ol>
  
  <p>One, I am not too happy with either approach: 1) I would prefer not to manage additional EC2 instances and process raw SQL changes. 2) I am planning to use constraints, optimistic concurrency and transactions for Aurora, which means that transactions can and will fail and rollback. However, the lambda_(a)sync calls will have been executed regardless of the transaction outcome.</p>
  
  <p>Any better ideas for Aurora? Or am I looking at this problem from the wrong angle?</p>
  
  <p>I would like to keep this question and discussion focused to the question of how to guarantee consistency between changes an the underlying data store and an outgoing stream with change events, not on Aurora vs. DynamoDB.</p>