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?
Asked
Active
Viewed 3,003 times
4
-
Can you please clarify what you mean by "Contract testing for the AWS lambdas" / "Contract Testing on AWS SAM"? As you may already know "Contract Testing" involves two parties, "consumer" and "provider". I am guessing AWS is playing the provider role here. Is your intention to stub / mock the AWS Lambdas and / or AWS SAM? Kindly add some details about what is your rough architecture (consumer, provider, etc.) and what you want to achieve. – HariKrishnan Dec 07 '22 at 07:52
2 Answers
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.

Matthew Fellows
- 3,669
- 1
- 15
- 18
0
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.

Shivang Agarwal
- 1,825
- 1
- 14
- 19