简体   繁体   English

无服务器解决方案 (AWS) 中的开发、暂存和生产环境

[英]Development, Staging and Production environments in serverless solutions (AWS)

I have developed an API using flask + postgreSQL and the users registration process was ministered by such infrastructure.我使用 flask + postgreSQL 开发了一个 API,用户注册过程由此类基础设施负责。 I then decided to change the infrastructure in general.然后我决定总体上改变基础设施。 I decided to use NestJS + dynamoDB + cognito.我决定使用 NestJS + dynamoDB + cognito。 In other words, I decided to go serverless, However, I am finding quite hard to understand how to organize my project into development.换句话说,我决定 go 无服务器,但是,我发现很难理解如何将我的项目组织到开发中。 staging and production environments.登台和生产环境。

To sum up, I have two questions总结一下,我有两个问题


  1. How to perform unit testing in serverless environments?如何在无服务器环境中进行单元测试?
  2. How to create a development mode for testing and developing features locally?如何创建在本地测试和开发功能的开发模式?

I will give an example for each question in order to clarify what my doubts are.我会为每个问题举一个例子,以澄清我的疑惑。

Example for (1) (1) 的示例

In the first architecture using flask + postgreSQL I created a script that would wipe out the entire local database and create a mock data with the goal of executing functions so the API could be tested.在使用 flask + postgreSQL 的第一个架构中,我创建了一个脚本,该脚本将清除整个本地数据库并创建一个模拟数据,目的是执行函数,以便可以测试 API。 But since I have no local environment, should I replicate the entire production environment in AWS in order to test it?但是由于我没有本地环境,我是否应该将整个生产环境复制到 AWS 中以进行测试?

Example for (2) (2) 的示例

Usually when I was testing new features in the API I would erase and create new mock data, and my coworkers would do the same in their local machines.通常当我在 API 中测试新功能时,我会擦除并创建新的模拟数据,而我的同事会在他们的本地机器上做同样的事情。 In other words, each developer had their local system ready to be "screwed" haha without disturbing other developers' work.换句话说,每个开发人员都准备好他们的本地系统,可以在不影响其他开发人员工作的情况下“搞砸”哈哈。 How could I do something similar in dynamoDB / serveless architecture?我怎么能在 dynamoDB/无服务器架构中做类似的事情?

If your tests involve relatively low amount of data being written and read to the table, you can do them using the real AWS, but just use a different table (and probably different account.) from your production table.如果您的测试涉及写入和读取到表的数据量相对较少,您可以使用真正的 AWS 进行测试,但只需使用与生产表不同的表(可能还有不同的帐户)。 The test table can be created and deleted in a matter of seconds.可以在几秒钟内创建和删除测试表。

However, if the tests involve a more substantial amount of data, testing this way can become expensive and slow - in which case you might prefer to have a local version of DynamoDB running on your own machine and connect to that in your tests.但是,如果测试涉及大量数据,这种方式的测试可能会变得昂贵且缓慢——在这种情况下,您可能更愿意在自己的机器上运行本地版本的 DynamoDB 并在测试中连接到该机器。 As far as I know, you have to options for a locally-installed DynamoDB:据我所知,您必须选择本地安装的 DynamoDB:

  1. Amazon provide DynamoDB Local . Amazon 提供DynamoDB Local This is a DynamoDB-compatible (sort of) database that cannot be used in any real deployment (it is too slow, no high-availability, etc.) but good enough for writing tests against it.这是一个兼容 DynamoDB 的(某种程度上)数据库,不能在任何实际部署中使用(它太慢,没有高可用性等),但足以针对它编写测试。
  2. ScyllaDB provides Alternator , an open-source DynamoDB-compatible database. ScyllaDB 提供了Alternator ,一个开源的 DynamoDB 兼容数据库。 This is a full-fledged database, with high performance, persistence and high-availability - so you can use it even for high-throughput test workloads, and you can also decide to use it for production, not just for testing (full disclosure - I'm one of the Alternator developers).这是一个成熟的数据库,具有高性能、持久性和高可用性——所以你甚至可以将它用于高吞吐量测试工作负载,你也可以决定将它用于生产,而不仅仅是用于测试(完全公开——我是交流发电机开发人员之一)。

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

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