AWS SAM - Test lambda was invoked, test kinesis event was created

Viewed 138

I'm investigating whether AWS SAM can be used within the context of an application I'm working on.

Basically the structure of the application is that you have things like:

[kinesis event] -> [my lambda] -> [invokes another lambda]

or

[kinesis event] -> [my lambda] -> [creates a different kinesis event]

or

[another lambda] => [invokes my lambda] => [invokes yet another lambda]

So what I want to be able to is write some tests like:

Given that I invoke myLambda with data ABC,
 then I expect otherLambda to have been invoked with DEF. 

or

Given that I put event ABC on the kinesis stream,
 then I expect that myLamdba was executed,
 and I expect that it put event DEF on the kinesis stream

While I can see all of the functionality for invoking lambdas locally, I can't see any functionality about making assertions against other lambdas being called etc.

Is this out of scope of what AWS SAM does?

1 Answers

Not sure if this will help but here's my two pence on the problem. Feel free to let me know if I completely missunderstood your question!

AWS SAM is only there to help you get your application into AWS, sure it will make local testing a bit easier / harder on some contexts but the idea is the same.

Consider that while you are working with 2+ lambdas invoking each other, they should be functions in the end so you'd argue they need to be independently testable. How I see it, you have a couple of options you can consider:

  • You put a queue between lambdas so that when you have a Kinesis event firing Lambda A doing some processing, then it can put a message and trigger Lambda B with the processed data.
  • You could explore the use of step functions and see if it fits your particular case.
  • Or finally your middle case on the question actually works, if you look on the event sources listed for Lambdas you can use Kinesis and then just fire another Kinesis event there if you will. (Depending on your use case this might be a better solution than queues)

TL;DR: Sam will do anything others already do, it's a matter of organising your functions and making sure they are not dependant on each other.

Related