KumologicaHQ / kumologica-support

3 stars 0 forks source link

Event Payload : mismatch #21

Open sharmmoh1983 opened 3 years ago

sharmmoh1983 commented 3 years ago

There is a mismatch of Event payload used by AWS lambda and Cognito Trigger Listener in Kumologica flow

For ex: Event message for AWS lambda Pre Sign up


{
    "level": "info",
    "datetime": "2021-07-13T06:15:13+00:00",
    "nodeId": "a570ffd2.006b4",
    "meta": {
        "environment": "xyz",
        "service": "xyz",
        "requestId": "xyz"
    },
    "message": {
        "Records": [
            {
                "version": "1",
                "region": "ap-southeast-2",
                "userPoolId": "xyz",
                "userName": "xyz",
                "callerContext": {
                    "awsSdkVersion": "aws-sdk-unknown-unknown",
                    "clientId": "CLIENT_ID_NOT_APPLICABLE"
                },
                "triggerSource": "PreSignUp_AdminCreateUser",
                "request": {
                    "userAttributes": {
                        "email_verified": "true",
                        "email": "xyz"
                    },
                    "validationData": null
                },
                "response": {
                    "autoConfirmUser": false,
                    "autoVerifyEmail": false,
                    "autoVerifyPhone": false
                }
            }
        ]
    }
}

Event message for Cognito Listener Pre Sign up : It is a subset of AWS Lambda Event Payload

 {
                "version": "1",
                "region": "ap-southeast-2",
                "userPoolId": "xyz",
                "userName": "xyz",
                "callerContext": {
                    "awsSdkVersion": "aws-sdk-unknown-unknown",
                    "clientId": "CLIENT_ID_NOT_APPLICABLE"
                },
                "triggerSource": "PreSignUp_AdminCreateUser",
                "request": {
                    "userAttributes": {
                        "email_verified": "true",
                        "email": "xyz"
                    },
                    "validationData": null
                },
                "response": {
                    "autoConfirmUser": false,
                    "autoVerifyEmail": false,
                    "autoVerifyPhone": false
                }
            }

This gap causes confusion in testing nodes locally as my code using xpath based on AWS Lambda event but I am testing using different Event payload.

It would be easy to comprehend if Test nodes give consistent payload to test

bjq-dev commented 3 years ago

Please clarify the difference, the first message is json log message that is composed of logger details (level, date time, nodeid), metadata and log message that contains event. By the look both: cognito event and content of the message looks the same,

Please note that event listener normalised events into Records[] array. This means the few events that are single objects will be put into Records[] array by event listener.

sharmmoh1983 commented 3 years ago

The difference is that I can't use the default event message of AWS lambda to test the Cognito node as i always get following error : Request cannot be processed by event listener and it creates confusion This is the event I am testing locally but xpath which is I am using in my flow is payload.Records[0]

{
    "version": "1",
    "region": "xyz",
    "userPoolId": "xyz",
    "userName": "xyz",
    "callerContext": {
        "awsSdkVersion": "aws-sdk-unknown-unknown",
        "clientId": "xyz"
    },
    "triggerSource": "PreSignUp_SignUp",
    "request": {
        "userAttributes": {
            "name": "xyz",
              "phone_number": "xyz"

        },
        "validationData": null
    },
    "response": {
        "autoConfirmUser": false,
        "autoVerifyEmail": false,
        "autoVerifyPhone": false
    }
} 

This leads to confusion that without having Records field in test data still my flow is working.

We should have common Event message to test flows which is not case now

bjq-dev commented 3 years ago

Event Listener has specific config details for Cognito originated event. You can specify what kind of trigger your flow expects, in this case it will be Pre-SignUp SignUp.

Event Listener will always normalise request into array of Records, the array will contain single record so you can access it: Records[0].

To test it, please use TestNode with exact event payload as specified by AWS, do not use HttpTestNode. I suspect the payload above has the correct structure of PreSignUp SignUp event.