Is there any way to do Contract testing for the AWS lambdas. Pact is being used for normal APIs, But I am trying to implement Contract Testing on AWS SAM. Is there any tool for this or Pact can be used with any modifications?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Yes, you can use Pact to do contract testing with Lambda.
For example, Pact JS has support for asynchronous programming and has an example for Lambda using the serverless framework [1].
There is a good intro article [2] on the matter also.
- [1] https://github.com/pact-foundation/pact-js/#asynchronous-api-testing
- [2] https://dius.com.au/2017/09/22/contract-testing-serverless-and-asynchronous-applications/
回答2:
You can use the amazon-cli if you want to test it.
amazon-cli will help you to manually trigger your lamda via aws lambda invoke the command.
Please install amazon-cli at your local from this link.
After that you can invoke the amazon 1st lamda from your cli with aws lamda command. It comes with many options like you can pass payload (supposed to be pass from SNS in actual scenario).
Executing AWS Lamda from Amazon-CLI Command details description
Example command:
aws lambda invoke --function-name your_function_name --invocation-type RequestResponse outfile.txt --payload file:requestFile.txt
I hope it helps.