[英]Automation testing for aws lambda functions in python
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. 我有一个aws lambda函数,它将在dynamodb中为s3存储桶中创建的每个对象写入s3文件元数据信息,为此我在s3存储桶上有事件触发器。 So i'm planning to automate testing using python. 所以我打算使用python自动化测试。 Can any one help out how I can automate this lambda function to test the following using unittest package. 任何人都可以帮助我如何使用unittest包自动化这个lambda函数来测试以下内容。
This can be done using moto
and unittest
. 这可以使用moto
和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. moto
将要做的是为AWS添加有状态模拟 - 您的代码可以继续像正常一样调用boto
,但实际上不会对AWS进行调用。 Instead, moto
will build up state in memory. 相反, moto
将在记忆中建立状态。
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
. 如果您正在为DynamoDB和S3构建功能,那么您将利用moto
的mock_s3
和mock_dynamodb2
方法。
I wrote up a tutorial on how to do this (it uses pytest
instead of unittest
but that should be a minor difference). 我写了一个关于如何做到这一点的教程(它使用pytest
而不是unittest
但这应该是一个小的区别)。 Check it out: joshuaballoch.github.io/testing-lambda-functions/ 看看: joshuaballoch.github.io/testing-lambda-functions/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.