I have Lambda Function which attached to DynamoDB change event. The Lambda is triggering twice when I change/modify an item in the Test-machines table in the DynamoDB.
I am modifying IsMachineOn
value from True
to False
, It is trigger Test-Machine-On-alert-status
Lambda function twice.
I am not understanding why two-time lambda is a trigger.
I observed a small change in the records
in the event
parameter of Lambda.
For first trigger,
Value of NewImage["IsMachineOn"]["BOOL"]
is False
Value of OldImage["IsMachineOn"]["BOOL"]
is True
For Second trigger,
Value of NewImage["IsMachineOn"]["BOOL"]
is False
Value of OldImage["IsMachineOn"]["BOOL"]
is False
I have business logic on NewImage["IsMachineOn"]["BOOL"]==False
so that my business logic is running twice.
There are two things:
- Why Lambda is running twice?
- What will be a workaround to fix this issue?
NewImage["IsMachineOn"]["BOOL"] == False && NewImage["IsMachineOn"]["BOOL"] != OldImage["IsMachineOn"]["BOOL"]
(is now off and also this is a state change event)... but it sounds as if a second, different update is triggering the second event, so you should probably review the other attributes, to identify the nature of that second event's trigger. This cannot -- by definition -- be a second Lambda trigger on the same event, if new and old differ in one and are the same in the other. – Michael - sqlbot