Structuring non-application specific infrastructure deployment with AWS CDK

huangapple go评论68阅读模式
英文:

Structuring non-application specific infrastructure deployment with AWS CDK

问题

Currently setting up CDK from scratch here and looking for justification and best practices from the trenches.
我目前正在从头开始设置CDK,并寻求来自实际经验的理由和最佳实践。

I have multiple apps which I will naturally have my CDK code and the app code in one repo (reeping the benefits of synonymous languages for app and infra code).
我有多个应用程序,我自然会将我的CDK代码和应用程序代码放在一个仓库中(以获取应用程序和基础设施代码的相似性语言带来的好处)。

But I am looking for tips on that generic infra.
但我正在寻找有关通用基础设施的建议。

Think the Sec Hub setup, Config rules, Alerting stacks, etc. Basically anything that does not have the app as a dependant.
考虑安全中心设置、配置规则、警报堆栈等等。基本上,任何与应用程序无关的内容。

How would you:
你会如何:

  • structure the repo (multiple apps, stacks or stages ?)

  • 结构化仓库(多个应用程序、堆栈或阶段?)

  • deploy these if you don't want to risk redeploying all when updating one ?

  • 如果您不想在更新一个时冒重新部署所有的风险,该如何部署它们?

  • tie this into CI/CD somehow ? If so, how ?

  • 如何将其与CI/CD集成?如果是这样,怎么做?

My thought is: one git repo (aws_infra for example), one CDK app, under which I have multiple stacks. Each stack represents a service. Then just deploying it with cdk deploy $yourstackname (or CI/CD equivalent), I guess if I define stacks with different environments, it can be deployed to multiple... well, environments.
我的想法是:一个Git仓库(例如aws_infra),一个CDK应用程序,其中包含多个堆栈。每个堆栈代表一个服务。然后只需使用cdk deploy $yourstackname(或CI/CD等效方式)进行部署,我猜如果我定义了具有不同环境的堆栈,它可以部署到多个……好吧,环境中。

Interested to hear how it would be best set up for
有兴趣听听如何最好地设置为

英文:

Currently setting up CDK from scratch here and looking for justification and best practices from the trenches.
I have multiple apps which I will naturally have my CDK code and the app code in one repo (reeping the benefits of synonymous languages for app and infra code).

But I am looking for tips on that generic infra.
Think the Sec Hub setup, Config rules, Alerting stacks, etc. Basically anything that does not have the app as a dependant.
How would you:

  • structure the repo (multiple apps, stacks or stages ?)
  • deploy these if you don't want to risk redeploying all when updating one ?
  • tie this into CI/CD somehow ? If so, how ?

My thought is: one git repo (aws_infra for example), one CDK app, under which I have multiple stacks. Each stack represents a service. Then just deploying it with cdk deploy $yourstackname (or CI/CD equivalent), I guess if I define stacks with different environments, it can be deployed to multiple... well, environments.
Interested to hear how it would be best set up for

答案1

得分: 0

你已经几乎回答了你自己的问题。我更喜欢使用一个具有多个堆栈的单个 CDK 应用程序的存储库,这些堆栈由构件构成。我们使用堆栈来分隔独立的代码块,例如网络堆栈、日志堆栈、数据库堆栈、应用程序1堆栈等,以便可以一起部署经常更改的内容。在堆栈之间传递参数很麻烦,要小心不要分开应该在一起的两个事物。

我建议阅读 文档页面 以了解使用 CDK 的最佳实践。"构建最佳实践" 部分将回答你的许多问题。

关于 CI/CD,您可以设置一些根据给定 PR 中更改的文件夹选择要部署的堆栈的内容。

英文:

You have almost answered you own question. I prefer to use one repository with a single CDK app with multiple stacks which then consist of constructs. We use stacks to separate independent blocks of code, such as a network-stack, a logging-stack, database-stack, application1-stack etc. such that we can deploy the stuff that changes often together. It is a hassle to pass parameters between stacks to be careful to not split two things that should be together.

I recommend to read the documentation page for best practices using CDK. The section Construct best practices will answer many of your questions.

Regading CI/CD, you could set up something that chooses the stack to deploy depending on what folders have changed in a given PR.

huangapple
  • 本文由 发表于 2023年5月24日 23:04:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76324952.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定