简体   繁体   English

AWS Lambda 开发工作流

[英]AWS Lambda Dev Workflow

I've been using AWS for a while now but am wondering about how to go about developing with Lambda.我已经使用 AWS 一段时间了,但我想知道如何使用 Lambda 进行开发。 I'm a big fan of having server-less functions and letting Amazon handle the maintenance and have been using it for a while.我非常喜欢拥有无服务器功能并让 Amazon 处理维护工作,并且已经使用了一段时间。 My question: Is there a recommended workflow for version control and development?我的问题:是否有推荐的版本控制和开发工作流程?

I understand there's the ability to publish a new version in Lambda.我知道可以在 Lambda 中发布新版本。 And that you can point to specific versions in a service that calls it, such as API Gateway.并且您可以指向调用它的服务中的特定版本,例如 API Gateway。 I see API Gateway also has some nice abilities to partition who calls which version.我看到 API Gateway 也有一些很好的功能来划分谁调用哪个版本。 ie Having a test API and also slowly rolling updates to say 10% of production API calls and scaling up slowly.即有一个测试 API 并且缓慢滚动更新,比如 10% 的生产 API 调用和缓慢扩展。

However, this feels a bit clunky for an actual version control system.然而,对于实际的版本控制系统来说,这感觉有点笨拙。 Perhaps the functions are coded locally and uploaded using the AWS CLI and then everything is managed through a third party version control system (Github, Bitbucket, etc)?也许函数是在本地编码并使用 AWS CLI 上传,然后一切都通过第三方版本控制系统(Github、Bitbucket 等)进行管理? Can I deploy to new or existing versions of the function this way?我可以通过这种方式部署到该函数的新版本或现有版本吗? That way I can maintain a separation of test and production functions.这样我就可以保持测试和生产功能的分离。

Development also doesn't feel as nice through the editor in Lambda.通过 Lambda 中的编辑器进行开发也感觉不那么好。 Not to mention using custom packages require to upload anyways.更不用说使用自定义包需要上传了。 Seems local development is the better solution.似乎本地开发是更好的解决方案。 Trying to understand others workflows so I can improve mine.尝试了解其他工作流程,以便改进我的工作流程。

How have you approached this issue in your experience?根据您的经验,您是如何处理这个问题的?

You can have version control on your lambda using aws CodeCommit (much simpler than using an external git repository system, although you can do either). 您可以使用aws CodeCommit对lambda进行版本控制(比使用外部git存储库系统简单得多,尽管你可以这样做)。 Here is a tutorial for setting up a CodePipeline for commit/build/deploy stages: https://docs.aws.amazon.com/codepipeline/latest/userguide/tutorials-simple-codecommit.html 以下是为提交/构建/部署阶段设置CodePipeline的教程: https ://docs.aws.amazon.com/codepipeline/latest/userguide/tutorials-simple-codecommit.html

This example deploys an EC2 instance, so for the deploy portion for a lambda, see here 此示例部署EC2实例,因此对于lambda的部署部分, 请参阅此处

If you set up a pipeline you can have an initial commit stage, then a build stage that runs your unit tests and packages the code, and then a deploy stage (and potentially more stages if required). 如果您设置了一个管道,您可以拥有一个初始提交阶段,然后是一个构建阶段,它运行您的单元测试并打包代码,然后是一个部署阶段(如果需要,可能还有更多阶段)。 It's a very organized way of deploying lambda changes. 这是一种非常有组织的部署lambda更改的方式。

I wrote roughly a dozen lambda functions that trigger based on S3 file write event or time, and make a HTTP req to an API to kickstart data processing jobs. 我写了大约十几个基于S3文件写入事件或时间触发的lambda函数,并对API进行HTTP req以启动数据处理作业。

I don't think there's any gold standard. 我认为没有任何黄金标准。 From my research, there are various approaches and frameworks out there. 根据我的研究,有各种方法和框架。 I decided that I didn't want to depend on any kind of frameworks like Serverless nor Apex because I didn't want to learn how to use those things on top of learning about Lambda. 我决定我不想依赖任何类型的框架,如无服务器和Apex,因为我不想学习如何在学习Lambda的基础上使用这些东西。 Instead I built out improvements organically based on my needs as I was developing a function. 相反,当我开发一个函数时,我根据自己的需要有机地构建了改进。

To answer your question, here's my workflow. 要回答你的问题,这是我的工作流程。

  1. Develop locally and git commit changes. 开发本地和git提交更改。
  2. Mock test data and test locally using mocha and chai. 使用mocha和chai模拟测试数据并在本地测试。
  3. Run a bash script that creates a zip file compressing files to be deployed to AWS lambda. 运行bash脚本,创建压缩要部署到AWS lambda的文件的zip文件。
  4. Upload the zip file to AWS lambda. 将zip文件上传到AWS lambda。

I would suggest you to have a look at SAM. 我建议你看看SAM。 SAM is a command line tool and a framework to help you to develop your serverless application. SAM是一个命令行工具和框架,可帮助您开发无服务器应用程序。 Using SAM, you can test your applications locally before to upload them to the cloud. 使用SAM,您可以在将应用程序上载到云之前在本地测试它们。 It also support blue / green deployment and CI/CD workflows, starting automatically from github. 它还支持从github自动启动的蓝/绿部署和CI / CD工作流。

https://github.com/awslabs/aws-sam-cli https://github.com/awslabs/aws-sam-cli

I think Serverless Framework + standard Git workflow is your best bet here. 我认为无服务器框架 +标准Git工作流程是您最好的选择。 Each Git branch is tied to a completely separate environment (or stage). 每个Git分支都绑定到一个完全独立的环境(或阶段)。 They can also be in different AWS accounts as well . 它们也可以位于不同的AWS账户中

Your team works in feature branches or uses a PR based workflow and your deploys are associated to Git commits. 您的团队在功能分支中工作或使用基于PR的工作流,并且您的部署与Git提交相关联。 This saves you the trouble of dealing with Lambda versioning. 这样可以省去处理Lambda版本控制的麻烦。

So locally you might deploy to a certain set of branches. 因此,您可以在本地部署到某组分支。 While for your staging and production environments you might want to connect them through your CI process. 对于您的登台和生产环境,您可能希望通过CI过程连接它们。

We've written about the Git workflow aspect of this in detail here - https://seed.run/blog/git-workflow-for-serverless-apps 我们在这里详细介绍了Git工作流方面的内容 - https://seed.run/blog/git-workflow-for-serverless-apps

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

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