AWS Lambda Event Source Triggers

Trigger at right moment whenever required
Photo by MIOPS Trigger on Unsplash

AWS Documentation states that user can only modify the state of following event source(s) added to Lambda.

Event Source(s) added to the Lambda with UUID

Rest of the Event Source(s) like SNS, EventBridge (Cloudwatch Event), etc., can be handled in different way. As they don’t have UUID setup. Click Here!

To move forward, I will assume that you have an AWS Account and AWS CLI knowledge. If you don’t, I suggest getting started here.

Follow/Execute the commands in an chronological order.

  1. Get the list of event source mappings associated with the lambda function by using following CLI command. (list-event-source-mappings CLI Documentation here)
> aws lambda list-event-source-mappings --function-name my-function

Output: Grab the UUID from the output.

{
"EventSourceMappings": [
{
"UUID": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE",
"StateTransitionReason": "USER_INITIATED",
"LastModified": 1569284520.333,
"BatchSize": 5,
"State": "Enabled",
"FunctionArn": "arn:aws:lambda:us-west-2:123456789012:function:my-function",
"EventSourceArn": "arn:aws:sqs:us-west-2:123456789012:mySQSqueue"
}
]
}

2. Paste the UUID in the following commands to enable/disable/delete — (update-event-source-mappings CLI Documentation here)

Note: It will take 60 seconds to update the state of lambda after a successful run of below commands.

  • Enable:
aws lambda update-event-source-mapping --function-name my-function --uuid a1b2c3d4-5678-90ab-cdef-11111EXAMPLE --enabled
  • Disable
aws lambda update-event-source-mapping --function-name my-function --uuid a1b2c3d4-5678-90ab-cdef-11111EXAMPLE --no-enabled
aws lambda delete-event-source-mapping --function-name my-function --uuid a1b2c3d4-5678-90ab-cdef-11111EXAMPLE

3. Check the Status after each step by using following command. (get-event-source-mappings CLI Documentation here)

aws lambda get-event-source-mapping --function-name my-function --uuid a1b2c3d4-5678-90ab-cdef-11111EXAMPLE

Output:

{
"EventSourceMappings": [
{
"UUID": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE",
"StateTransitionReason": "USER_INITIATED",
"LastModified": 1569284520.333,
"BatchSize": 5,
"State": "Enabled",
"FunctionArn": "arn:aws:lambda:us-west-2:123456789012:function:my-function",
"EventSourceArn": "arn:aws:sqs:us-west-2:123456789012:mySQSqueue"
}
]
}

In Summary, to modify the state of Lambda — SQS trigger fetch the UUID and disable/enable/delete through Lambda CLI commands stated above.