title: Counting AWS lambda calls and segmenting data per api key
body: <p>Customers (around 1000) sign up to my service and receive a customer unique api key. They then use the key when calling a AWS lambda function through AWS api gateway in to access data in DynamoDb. </p>
  
  <p><strong>Requirement 1</strong>: The customers get billed by the number of api calls, so I have to be able to count those. AWS only provides metrics for total number of api calls per lambda so I have a few options:</p>
  
  <ol>
  <li>At every api hit increment a counter in DynamoDB.</li>
  <li>At every api hit enqueue a message in SQS, receive it in "hit
  counter" lambda and increment a counter in DynamoDB.</li>
  <li>Deploy a separate lambda for each customer. Use AWS built-in call
  counter.</li>
  </ol>
  
  <p><strong>Requirement 2</strong>: The data that the lambda can access is unique for each customer and thus dependent on the api key provided.
  To enable this I also have a number of options:</p>
  
  <ol>
  <li>Store the required api key together with the data that the customer
  has the right to access.</li>
  <li>Deploy a separate lambda for each customer. Use api gateway to
  protect it with a key.</li>
  <li>Create a separate endpoint in api gateway for each customer, protect
  it with the api key.</li>
  </ol>
  
  <p>None of the options above seem like a good way to design the solution. Is there a canonical way of doing this? If not, which of the options above is the best? Have I missed an obvious solution due to my unfamiliarity with AWS?</p>