简体   繁体   English

对涉及 SQS 和 DynamoDB 的数据管道进行本地 Lambda 测试的建议

[英]Advice on local Lambda testing for data pipeline that involves SQS and DynamoDB

Other devs and I are currently testing/building lambda functions for cleaning data that flows from S3 -> SQS -> Data Router Lambda(python), DynamoDB Rules Engine, and then a text processor in Lambda.其他开发人员和我目前正在测试/构建 lambda 函数,用于清理来自 S3 -> SQS -> 数据路由器 Lambda(python)、DynamoDB 规则引擎,然后是 Lambda 中的文本处理器的数据。 We're currently working on the AWS platform but I'm trying to test this part of the data pipeline locally.我们目前正在使用 AWS 平台,但我正在尝试在本地测试这部分数据管道。

Ideally simulating S3 and SQS and dumping the zip files and running it through the lambda function.理想情况下模拟 S3 和 SQS 并转储 zip 文件并通过 lambda function 运行它。 Currently toying with the SAM-CLI and Visual Studio, but nothing's stuck yet.目前正在玩弄 SAM-CLI 和 Visual Studio,但还没有任何问题。 Any tips?有小费吗?

There are several ways you can approach (local) testing of your AWS application:您可以通过多种方式对 AWS 应用程序进行(本地)测试:

  1. Use unit tests for the different parts of your "pipeline", mocking the other parts like DynamoDB, SQS, etc.对“管道”的不同部分使用单元测试,mocking 其他部分,如 DynamoDB、SQS 等。
  2. Use something like LocalStack .使用类似LocalStack的东西。
  3. Every developer has their own "developer environment" in AWS.每个开发人员在 AWS 中都有自己的“开发人员环境”。 You could for example prefix every resource with the name of the developer ( john_processing_lambda ).例如,您可以在每个资源前加上开发人员的名称 ( john_processing_lambda )。 You deploy to AWS and run integration tests from your local machine.您部署到 AWS 并从本地计算机运行集成测试。 You can achieve something like this with tools like Terraform , which allow you to "dynamically" name resources and for example add prefixes with the developers name.您可以使用Terraform 之类的工具来实现类似的目的,它允许您“动态地”命名资源,例如添加带有开发人员名称的前缀。

Personally, I think running "AWS on your local machine" via Docker containers or tools like LocalStack not really satisfying.就个人而言,我认为通过 Docker 容器或诸如 LocalStack 之类的工具运行“在您的本地计算机上的 AWS”并不是很令人满意。 We had the best results with a combination of option 1 and option 3. Both have the upside that you can use the same tests in your CI/CD pipeline.结合使用选项 1 和选项 3,我们获得了最好的结果。两者都有优点,您可以在 CI/CD 管道中使用相同的测试。

Furthermore, not running in the actual cloud (AWS) always bears the risk of "forgetting" something.此外,不在实际的云 (AWS) 中运行总是要承担“忘记”某些事情的风险。 Most notably IAM permissions.最值得注意的是 IAM 权限。 So everything runs fine on your local machine, but then it does not work on AWS.所以一切都在您的本地机器上运行良好,但它在 AWS 上不起作用。

Deploying a separate environment for every developer, so that they can play around with the actual resources and run tests directly in AWS, would be my recommendation.我的建议是为每个开发人员部署一个单独的环境,以便他们可以使用实际资源并直接在 AWS 中运行测试。 This paired with solid unit tests should yield the best results.这与可靠的单元测试相结合应该会产生最好的结果。

The downside of developer environments in AWS is that a developer has to deploy their code to AWS every time they want to test something. AWS 中的开发人员环境的缺点是开发人员每次想要测试某些东西时都必须将他们的代码部署到 AWS。 So making deployments fast is important.因此,快速部署很重要。 I found that with sufficient experience, you don't need to deploy that often anymore and this becomes less of an issue.我发现,有了足够的经验,您就不需要再频繁地进行部署,这不再是一个问题。 Nevertheless, developer satisfaction in your team is important, so make sure to make this as smooth as possible.尽管如此,团队中的开发人员满意度很重要,因此请确保尽可能顺利。

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

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