4

I have a lambda setup that uses vendia serveless-express as a handler. It has been working well to serve REST APIs from the single lambda function with multiple routes.

I now have a new requirement, where the same lambda needs to be part of a step function's state machine. But that doesn't seem to be allowed by vendia app, as it always throws the error: "Unable to determine event source based on event" as it expects the event to be api gateway / alb only.

So, based on this, it looks like I will need a separate lambda for step, which makes me have duplicate code in multiple lambdas.

Is it possible for the lambda to handle the inputs from step and still be a vendia express app? Please let me know if I am trying something that doesn't make sense at all.

zenbeni
  • 7,019
  • 3
  • 29
  • 60

1 Answers1

0

If I were you I would just implement my own converter that transforms a StepFunction event into an API Gateway event and then calling the express-serverless in your lambda.

The package aws-lambda contains definitions in TypeScript of many AWS events including those ones, then try to generate a mock API Gateway event from your own step function event value. From the sources (4.3.9) we have the function:

function getEventSourceNameBasedOnEvent ({
  event
}) {
  if (event.requestContext && event.requestContext.elb) return 'AWS_ALB'
  if (event.Records) return 'AWS_LAMBDA_EDGE'
  if (event.requestContext) {
    return event.version === '2.0' ? 'AWS_API_GATEWAY_V2' : 'AWS_API_GATEWAY_V1'
  }

  throw new Error('Unable to determine event source based on event.')
}

So probably to make it work correctly, you have to define a RequestContext mock value in your mock event and it should be enough.

zenbeni
  • 7,019
  • 3
  • 29
  • 60