title: How to limit the number of times an AWS Lambda Function can be triggered within a specific timeframe
body: <p>I’m working to build an automated process sends a PUT to a rest API when an object is detected by the DeepLens. </p>
  
  <p>DeepLens → IoT → SNS → Lambda → External Rest API</p>
  
  <p>DeepLens is performing object detection. I am running IoT Rules that sends a message to an SNS topic when specific objects are detected. The SNS topic sends an SMS, an Email and triggers a Lambda function. The Lambda function performs a PUT against an external rest API. </p>
  
  <p>I am trying to limit the number of times the lambda function can perform the PUT to once per 60 seconds. Example Lambda code below if</p>
  
  <pre><code>import http.client
  import mimetypes
  def lambda_handler(event, context):
    conn = http.client.HTTPSConnection("api.who.what")
    payload = " {\"id\" : \"SANITIZED\", \"duration\" : 60}"
    headers = {
      'Authorization': 'Bearer SANITIZED',
      'Content-Type': 'text/plain'
    }
    conn.request("PUT", "/1/get/going/start", payload, headers)
    res = conn.getresponse()
    data = res.read()
    print(data.decode("utf-8"))
  </code></pre>