[英]Running/Testing an AWS Serverless API written in Terraform
No clear path to do development in a serverless environment.在无服务器环境中进行开发没有明确的途径。
I have an API Gateway backed by some Lambda functions declared in Terraform. I deploy to the cloud and everything is fine, but how do I go about setting a proper workflow for development?我有一个 API 网关,它由 Terraform 中声明的一些 Lambda 函数支持。我部署到云端,一切都很好,但是我 go 如何设置适当的开发工作流程? It seems like a struggle to push every small code change to the cloud while developing in order to run your code.
在开发过程中将每个小的代码更改推送到云端以运行您的代码似乎是一场斗争。 Terraform has started getting some support by the SAM framework to run your Lambda functions locally ( https://aws.amazon.com/blogs/compute/better-together-aws-sam-cli-and-hashicorp-terraform/ ), but still no way to simulate a local server and test out your endpoints in Postman for example.
Terraform 已开始获得 SAM 框架的一些支持,以在本地运行 Lambda 函数 ( https://aws.amazon.com/blogs/compute/better-together-aws-sam-cli-and-hashicorp-terraform/ ),但是例如,仍然无法模拟本地服务器并测试 Postman 中的端点。
First of all I use serverless plugin instead of terraform, my answer is based on what you provided and what I found around.首先,我使用无服务器插件而不是 terraform,我的回答基于您提供的内容和我在周围找到的内容。
From what I understood so far with priovided documentation you are able to run sam CLI with terraform (cf: Chapter Local testing )根据我目前对 priovided 文档的理解,您可以使用 terraform 运行 sam CLI(参见:Chapter Local testing )
You might follow this documentation to invoke local functions.您可以按照此文档来调用本地函数。
I recommend to use JSON files to create use cases instead of stdin injection.我建议使用 JSON 文件来创建用例而不是标准输入注入。 First step is to create your payload in json file and to invoke your lambda with the json payload like
第一步是在 json 文件中创建您的有效载荷,并使用 json 有效载荷调用您的 lambda,例如
sam local invoke "YOUR_LAMBDA_NAME" -e ./path/to/yourjsonfile.json
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.