title: How to reduce latency on AWS Lambda with python
body: <p>I'm trying to reduce latency of my Lambda python function, essentially queuing up the task and returning as fast as possible.</p>
  
  <p>The lambda function receives a relatively small payload via the API gateway.</p>
  
  <p>I've tried a few things, but all seem to result in ±200ms latency:</p>
  
  <ul>
  <li>pushing a message to SQS with the event data</li>
  <li>invoking another lambda function using boto3 <code>client.invoke</code> with <a href="http://boto3.readthedocs.org/en/latest/reference/services/lambda.html#Lambda.Client.invoke" rel="nofollow"><code>InvocationType='Event'</code></a> (which should invoke asynchronously)</li>
  <li>publishing an SNS message</li>
  </ul>
  
  <p>Latency was measured after the lambda function was "warm". I also measured and compared with:</p>
  
  <ul>
  <li>returning without doing anything (&lt;1ms)</li>
  <li>returning after pushing to redis on redislabs (~3-20ms)</li>
  </ul>
  
  <p>A potential solution is to use redis as a queue instead of SQS, but I still wonder if I could improve latency for this use-case within the AWS toolset, or perhaps I did something wrong and shouldn't expect this kind of latency with SNS/SQS/Lambda invocation?</p>
  
  <p>EDIT: here's a <a href="https://gist.github.com/gingerlime/d6d2e89d10e9d7a0b056e84000f30bce" rel="nofollow">gist</a> with the inline code used for invoking another lambda function. Execution time around 150ms ...</p>