简体   繁体   English

使用 CDK、AWS 和 Github 私有存储库部署的最佳实践?

[英]Best practice deploying using CDK, AWS, and Github private repos?

I am not quite clear on the best practices related to using CDK to deploy private Github repos to AWS.我不太清楚与使用 CDK 将私有 Github 存储库部署到 AWS 相关的最佳实践。 I understand that a pipeline should be created by CDK and the pipeline should invoke CodeDeploy to deploy the assets, but beyond that the details are murky.我知道管道应该由 CDK 创建,并且管道应该调用 CodeDeploy 来部署资产,但除此之外,细节还不清楚。

I also want to understand if for this use case it would make sense to have a separate CDK repo which is responsible for the infrastructure for the entire backend of my project, or if it would make more sense to have CDK code included in each individual component repo.我还想了解对于这个用例,是否有一个单独的 CDK 存储库负责我项目的整个后端的基础设施,或者是否将 CDK 代码包含在每个单独的组件中更有意义回购。 As I will be utilizing a microservice/cell based approach for building out components, the overhead required in adding CDK configuration for each component might be substantial.由于我将使用基于微服务/单元的方法来构建组件,因此为每个组件添加 CDK 配置所需的开销可能很大。

You can think of CDK as a compiler that takes a given language and 'compiles' it down to CloudFormation templates.您可以将 CDK 视为采用给定语言并将其“编译”为 CloudFormation 模板的编译器。 Those templates are then uploaded to Cloudformation by the CDK framework, and run for you when you execute the deploy command.这些模板随后由 CDK 框架上传到 Cloudformation,并在您执行deploy命令时为您运行。

So.所以。 To answer your question more directly - if you can figure out how to do it in cloudformation, you can do it.更直接地回答你的问题——如果你能弄清楚如何在 cloudformation 中做到这一点,你就可以做到。 That may involve spinning up a code build and running a script that executes some api calls or prepares a package for an ec2 server that then uses that package in the next step or any number of things.这可能涉及启动代码构建并运行脚本,该脚本执行一些 api 调用或为 ec2 服务器准备 package,然后在下一步或 8 中使用该 ZEFE90A8E604A7C840E88ZD03A67F6B7D。

But remember that CDK synths its cloudformation template all at once, and is only creating the template.但请记住,CDK 会一次性合成其 cloudformation 模板,并且只是创建模板。 It does not run any scripts that may be part of your code builds, and it does not 'wait' for certain things to be complete - because it isn't doing anything like that.它不运行任何可能是您的代码构建的一部分的脚本,并且它不会“等待”某些事情完成 - 因为它没有做任何类似的事情。 If you have a sequence of events that need to occur, you want to use CodePipeline to orchestrate those events for you - but you can set up your CodePipeline with CDK for certain!如果您有一系列需要发生的事件,您想使用 CodePipeline 为您编排这些事件 - 但您可以使用 CDK 设置您的 CodePipeline!

As for Overhead, maybe at first.至于开销,也许一开始。 But trust me when I say it becomes very quick and easy to generate a CDK stack for a given microservice with experience, and its super handy.但是相信我,当我说为具有经验的给定微服务生成 CDK 堆栈变得非常快速和容易时,它超级方便。 Being able to spin up an ad-hoc on demand testing environment is super useful.能够启动一个临时的按需测试环境非常有用。 Being able to deploy individual stacks on demand and make quick changes with just a line of code is handy as all get out.能够按需部署单独的堆栈并只需一行代码即可进行快速更改,因为所有这些都可以使用。 Having a single source of code for both your prod and development environments that you make a change in one and on next deployment in each is automatically reflected is super handy.为您的产品和开发环境提供单一的代码源,您在其中一个中进行更改,并且在每个环境中的下一次部署时自动反映是非常方便的。

CDK is a very powerful tool - but it is a very low level one. CDK 是一个非常强大的工具——但它是一个非常低级的工具。 It creates the template that will create your resources.它创建将创建您的资源的模板。 Thats it.而已。 If your resources need to do something after being created for something else to happen you have to make use of other services to orchestrate that (CodePipeline, StepFunctions, Cloudwatch Events, ect)如果您的资源在创建后需要做某事以发生其他事情,您必须使用其他服务来编排(CodePipeline、StepFunctions、Cloudwatch Events 等)

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

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