Search code examples
pythonamazon-web-servicesboto3aws-sam-climoto

How to develop lambda functions that depend on AWS triggers?


Lambda functions often get triggered by several AWS events (e.g an EventBridge event).

I am developing a python lambda that once triggered by an EventBridge event (that matches a pattern for Security Hub), creates tickets on Jira.

My question is: How can one develop a such function, locally, without having the actual triggers? Is there a way to mock the EventBridge Events?

I am aware of the existence of moto (https://github.com/spulec/moto) but I have a hard time understanding how it works


Solution

  • Lambda-functions can be invoked locally like any other Python function, as long as you know the input-parameters. Some example events that are send by SecurityHub can be found here: https://docs.aws.amazon.com/securityhub/latest/userguide/securityhub-cwe-event-formats.html

    Mocking EventBridge could be simply done by manually curating a set of representative events, based on that format, and verifying that the Lambda-function behaves as it should when invoked with one of those events.


    Moto mocks all boto3-calls for you, and mimicks the AWS behaviour as closely as possible. That means you can execute any of your business logic as part of your tests, without having to worry about creating resources in AWS, and without having to mock things manually.

    Some simple examples can be found here: http://docs.getmoto.org/en/latest/docs/getting_started.html

    However:
    Moto does not yet implement the EventBridge->Lambda implementation, so that will not help you in this situation. (Only CloudWatch/SQS integration is supported as of version 2.3.0).