Answers: <p>Call Lambda's <a href="https://docs.aws.amazon.com/lambda/latest/dg/API_UpdateEventSourceMapping.html" rel="nofollow noreferrer">UpdateEventSourceMapping</a> API with the <code>{&quot;Enabled&quot;:true/false}</code> request body.</p>
  <p>If, for some reason, you want your own API for this, you can create one in API Gateway as described below.</p>
  <p>Before you begin, you need the UUID of the event source mapping you wish to enable/disable. Use the AWS CLI to get this (it isn’t shown on the UI):</p>
  <pre><code>aws lambda list-event-source-mappings --function-name my-func
  </code></pre>
  <pre><code>{
      &quot;EventSourceMappings&quot;: [
          {
              &quot;UUID&quot;: &quot;b962dcee-173c-47r1-9600-5c6d81catf85&quot;,
              &quot;BatchSize&quot;: 1,
              &quot;EventSourceArn&quot;: &quot;arn:aws:sqs:us-east-1:123456789012:my-queue&quot;,
              &quot;FunctionArn&quot;: &quot;arn:aws:lambda:us-east-1:123456789012:function:my-func&quot;,
              &quot;LastModified&quot;: 1595058588.141,
              &quot;State&quot;: &quot;Enabled&quot;,
              &quot;StateTransitionReason&quot;: &quot;USER_INITIATED&quot;
          }
      ]
  }
  </code></pre>
  <p>Next, either create a new API in API Gateway or add a resource &amp; a GET method to your existing API. Configure it as shown below. The UUID you got above is highlighted below:</p>
  <p><a href="https://i.sstatic.net/ifgvO.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ifgvO.png" alt="enter image description here" /></a></p>
  <p>The execution role shown above must allow API Gateway to invoke Lambda APIs.</p>
  <p>Scroll further down &amp; provide this mapping template:</p>
  <pre><code>Content-Type: application/json
  </code></pre>
  <pre><code>{
      &quot;Enabled&quot; : $input.params(&quot;Enabled&quot;)
  }
  </code></pre>
  <p>Save &amp; deploy to a stage. Now you can hit this API with the query param <code>Enabled=true</code> / <code>Enabled=false</code> to enable/disable your Lambda's SQS trigger. Here's a test done from the API Gateway console:</p>
  <p><a href="https://i.sstatic.net/CGilw.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/CGilw.png" alt="enter image description here" /></a></p>
  <p>For a detailed screenshot-guided walkthrough of this entire process, see <a href="https://harishkm.in/2020/07/18/enable-disable-aws-lambda-triggers-programmatically-by-invoking-an-api/" rel="nofollow noreferrer">my blog post</a>.</p>
  
Answers: CC BY-SA 4.0
Answers: 2020-10-06T22:34:09.737Z
Answers: Just to clarify you need to attach a lambda trigger to the sqs prior to running the `aws lambda list-event-source-mappings --function-name my-func` command. if you have multiple queues mapped to the same function all of the uuids will be returned and you can use them as desired.
Answers: Xitcod13
Answers: CC BY-SA 4.0
Answers: 2020-10-07T18:05:25.277Z
Answers: Additionally if youre triggering from lambda you must include permissions in your role. You can create a policy similar to the "DevelopEventSourceMappings" except remove the `Condition`. https://docs.aws.amazon.com/lambda/latest/dg/access-control-identity-based.html
Answers: Xitcod13
Answers: CC BY-SA 4.0
Answers: 2020-07-18T10:31:43.133Z
Answers: 2020-07-18T10:31:43.133Z
Answers: Harish KM
Body: <p>I have a requirement where I want to stop my lambda from receiving messages from SQS. And I want to implement this like an API which can toggle between the disabling and enabling of the AWS Lambda getting triggered by SQS. I tried looking for options but there were suggestions telling to invoke the permission which I don't find feasible.</p>
  
Tags: <amazon-web-services><aws-lambda><aws-iam><serverless><amazon-sqs>
Title: How to programmatically enable and disable SQS triggering AWS Lambda?
UserDisplayName: Sankalp Kotewar
ThreadText: # How to programmatically enable and disable SQS triggering AWS Lambda?
  
  (Asked by: username_0 on 2020-07-18)
  
  I have a requirement where I want to stop my lambda from receiving messages from SQS. And I want to implement this like an API which can toggle between the disabling and enabling of the AWS Lambda getting triggered by SQS. I tried looking for options but there were suggestions telling to invoke the permission which I don't find feasible.
  
  **Tags:** amazon-web-services, aws-lambda, aws-iam, serverless, amazon-sqs
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-07-18. Score: 2 | Accepted answer
  
  Call Lambda's [UpdateEventSourceMapping](https://docs.aws.amazon.com/lambda/latest/dg/API_UpdateEventSourceMapping.html) API with the `{"Enabled":true/false}` request body.
  
  If, for some reason, you want your own API for this, you can create one in API Gateway as described below.
  
  Before you begin, you need the UUID of the event source mapping you wish to enable/disable. Use the AWS CLI to get this (it isn’t shown on the UI):
  
  ```
  aws lambda list-event-source-mappings --function-name my-func
  
  ```
  
  ```
  {
      "EventSourceMappings": [
          {
              "UUID": "b962dcee-173c-47r1-9600-5c6d81catf85",
              "BatchSize": 1,
              "EventSourceArn": "arn:aws:sqs:us-east-1:123456789012:my-queue",
              "FunctionArn": "arn:aws:lambda:us-east-1:123456789012:function:my-func",
              "LastModified": 1595058588.141,
              "State": "Enabled",
              "StateTransitionReason": "USER_INITIATED"
          }
      ]
  }
  
  ```
  
  Next, either create a new API in API Gateway or add a resource & a GET method to your existing API. Configure it as shown below. The UUID you got above is highlighted below:
  
  [![enter image description here](https://i.sstatic.net/ifgvO.png)](https://i.sstatic.net/ifgvO.png)
  
  The execution role shown above must allow API Gateway to invoke Lambda APIs.
  
  Scroll further down & provide this mapping template:
  
  ```
  Content-Type: application/json
  
  ```
  
  ```
  {
      "Enabled" : $input.params("Enabled")
  }
  
  ```
  
  Save & deploy to a stage. Now you can hit this API with the query param `Enabled=true` / `Enabled=false` to enable/disable your Lambda's SQS trigger. Here's a test done from the API Gateway console:
  
  [![enter image description here](https://i.sstatic.net/CGilw.png)](https://i.sstatic.net/CGilw.png)
  
  For a detailed screenshot-guided walkthrough of this entire process, see [my blog post](https://username_1.in/2020/07/18/enable-disable-aws-lambda-triggers-programmatically-by-invoking-an-api/).
  
  > **Comments:**
  > **username_2**: Just to clarify you need to attach a lambda trigger to the sqs prior to running the `aws lambda list-event-source-mappings --function-name my-func` command. if you have multiple queues mapped to the same function all of the uuids will be returned and you can use them as desired.  
  > **username_2**: Additionally if youre triggering from lambda you must include permissions in your role. You can create a policy similar to the "DevelopEventSourceMappings" except remove the `Condition`. https://docs.aws.amazon.com/lambda/latest/dg/access-control-identity-based.html  
  
  ---
  
  