简体   繁体   English

“生产化” Lambda 和 API 网关

[英]"Productionising" Lambda and API Gateway

I have recently been teaching myself how to build APIs using NodeJS + Express.我最近一直在自学如何使用 NodeJS + Express 构建 API。 I am still very much a novice but was really excited when they worked brilliantly in my dev environment.我仍然是一个新手,但当他们在我的开发环境中出色地工作时,我真的很兴奋。 However, I struggled to know what and how to configure my server and codebase for production.但是,我很难知道如何以及如何配置我的服务器和代码库以进行生产。 There is lots of info out there to use things like Helmet and put NGINX in front as a proxy but some of those things are beyond me at this stage.有很多信息可以使用 Helmet 之类的东西,并将 NGINX 作为代理放在前面,但在现阶段,其中一些东西超出了我的范围。

So I started to look at 'serverless' as a possible option for deploying them and have migrated my data to an AWS RDS PostgreSQL and setup a Lambda function that takes a query parameter and queries the database.因此,我开始将“无服务器”视为部署它们的可能选项,并将我的数据迁移到 AWS RDS PostgreSQL 并设置了一个 Lambda 函数,该函数接受一个查询参数并查询数据库。 I have also managed to configure AWS API Gateway that expects an API key to trigger the Lambda function.我还设法配置了需要 API 密钥来触发 Lambda 函数的 AWS API 网关。

My RDS and Lambda functions are restriction to a VPC, I am using an API Key and API Gateway defaults to HTTPS.我的 RDS 和 Lambda 函数仅限于 VPC,我使用的是 API 密钥,API 网关默认为 HTTPS。

So I was after any advice or help on what other things I now need to consider as most of the traditional production challenges have been removed by using "serverless".因此,由于使用“无服务器”已经消除了大多数传统生产挑战,因此我就我现在需要考虑的其他事项寻求任何建议或帮助。

Here are some other things to think about:这里有一些其他的事情需要考虑:

  1. Use stages and stage variables to set up a 'pipeline' in the application.使用阶段和阶段变量在应用程序中设置“管道”。 In API Gateway, the stages are meant to represent this workflow, so you can have a beta stage and a prod stage.在 API Gateway 中,阶段旨在代表此工作流程,因此您可以拥有 beta 阶段和 prod 阶段。 You can use stage variables to set up the Lambda function endpoints in the same way .您可以使用阶段变量以相同的方式设置 Lambda 函数端点
  2. If you aren't already using Usage Plans , that is a good way to monitor usage by API Key and also set up rate limiting and quotas per API Key.如果您尚未使用Usage Plans ,这是通过 API Key 监控使用情况以及设置每个 API Key 的速率限制和配额的好方法。
  3. API Gateway and Lambda both publish CloudWatch metrics and logs, so you can monitor those and set up Alarms on the metrics as well. API Gateway 和 Lambda 都发布 CloudWatch 指标和日志,因此您可以监控它们并针对指标设置警报。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM