I have a aws lambda function which will write s3 file metadata information in dynamodb for every object created in s3 bucket, for this I have event trigger on s3 bucket. So i'm planning to automate testing using python. Can any one help out how I can automate this lambda function to test the following using unittest package.
This can be done using moto
and unittest
. What moto
will do is add in a stateful mock for AWS - your code can continue calling boto
like normal, but calls won't actually be made to AWS. Instead, moto
will build up state in memory.
For example, you could
If you're building functionality for both DynamoDB and S3, you'd leverage both the mock_s3
and mock_dynamodb2
methods from moto
.
I wrote up a tutorial on how to do this (it uses pytest
instead of unittest
but that should be a minor difference). Check it out: joshuaballoch.github.io/testing-lambda-functions/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.