Unit and Integration Testing for AWS Lambda
Ben Kehoe
2045

Hi Ben Kehoe,

thank you for the interesting article.

I would recommend to use the moto library, though. You won’t need any boto wrapper or hack. Your Lambda function code will simply use boto and you only need to decorate your tests.

Assuming that your Lambda function only calls S3 endpoints:

from moto import mock_s3
from lambda_function import lambda_handler
@mock_s3
def my_test():
lambda_handler()

and you can do the same for EC2, DynamoDB, etc.

I think this is a best practice that will help you keep the production code cleaner and your tests more elegant.

Also, you can always convert the decorator into a with statement — eventually based on an environment switching condition — in order to disable mocking.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.