简体   繁体   English

运行/测试用 Terraform 编写的 AWS 无服务器 API

[英]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.

相关问题 Terraform 无服务器应用程序与 AWS Lambda 和 API 网关未知令牌? - Terraform Serverless Applications with AWS Lambda and API Gateway unknown token? terraform aws serverless v2 多可用区 - terraform aws serverless v2 multi AZ 如何使用无服务器框架通过 AWS API 网关在 Node.js 中编写的 AWS Lambda function 上返回错误? - How do I return errors on an AWS Lambda function written in Node.js through the AWS API Gateway using the Serverless framework? AWS::Serverless::Api 和 AWS::Serverless::HttpApi 有什么区别? - What is the difference between AWS::Serverless::Api and AWS::Serverless::HttpApi? Terraform AWS Aurora 无服务器 MySQL - 错误:无效的数据库引擎 - Terraform AWS Aurora Serverless MySQL - Error: Invalid DB Engine 在 AWS Aurora Serverless 上运行的 Postgresql 重建索引 - Rebuilding Indexes in Postgresql running on AWS Aurora Serverless AWS API 网关集成和 Terraform - AWS API Gateway Integration and Terraform AWS - 无服务器离线框架上可用的 API 个密钥? - AWS - API keys available on the Serverless Offline framework? 在 AWS CodeBuild 中运行 Terraform - 部署 lambda - Running Terraform in AWS CodeBuild - deploying lambda Terraform,AWS RDS aurora mysql 无服务器异常“找不到源集群” - Terraform , AWS RDS aurora mysql serverless exception "source cluster could not be found"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM