@types/aws-lambda
lists the Event type for 34 different sources, from ALB to SQS, but SFN or StepFunctions is not on the list.
I just want to be able to (confidently) write
export const hander:Handler<SFNEvent> = (event) => {
Anybody know where this is?
Step Functions does not impose any restrictions on the type of the “event”, which Step Functions calls the “payload”, except I suppose that it must be expressible in JSON. Consider the following state-machine:
{
"StartAt": "InvokeVendor",
"States": {
"InvokeVendor": {
"Type": "Task",
"InputPath": "$",
"ResultPath": "$.vendorResult",
"Resource": "arn:aws:states:::lambda:invoke-vendor",
"Parameters": {
"FunctionName": "arn:aws:lambda:us-east-1:011668294191:function:vendor-webhook",
"Payload": {
"path": "process-webhook"
}
}
}
}
}
The handler for this could be written as:
export const handler: Handler<{ path: string }> = async (event, context, callback) => {
const route = routes[event.path];
if (!route) {
throw new Error(`Path ${event.path} not understood`);
}
return route(event, context, callback);
};
(Note the pattern used here, of passing in a path
and then using that to dispatch to a function that does the actual work, is by no means necessary, but is a handy way to reduce the number of separate Lambdas a complex project will require.)
Thanks to @STerliakov for explaining this to me.