How to force datatype when passing data as an event


#1

In my project I need to be able to pass a 5-digit numerical string as the event data. I’m using the following command:

serverless invoke local -f myFunction -s dev -d "55555"

It invokes this function:

function myFunction(event, context, callback) {
    console.log("event: " + event);
    console.log("datatype: " + typeof event);
}

Which prints out:

event: 55555
datatype: number

It seems that the event gets automatically parsed into a number datatype, even though the documentation seems to suggest that it should be passed as a String to the function. Where I run into issues is when I try to pass in a 5-digit number that starts with a 0. If I pass in, say, “04324”, it will leave off the preceding 0, giving me only the 4-digit number 4324.

Is there a way to force it to pass the 5-digit number to the event as a string, rather than a number? Or is there any other way to prevent it from dropping the preceding 0, even if it remains a number datatype?