I’ve been trying to solve this problem across three companies so far, and further I go, I get more confused, especially at how much the engineering community doesn’t seem to care about this principle.
As the title says, I’m trying to implement the ‘Build Once, Deploy Anywhere’ principle. In other words, I want to be sure whatever I have on a lower environment (e.g. test or acceptance) can be replicated exactly as-is on a higher environment (e.g. production), which is called a promotion.
The main problem with CDK is that it synthesizes an environment-specific template. Basically, there’s no way to parameterise a produced template, in order for it to be reusable. Basically, it’s against their philosophy:
Using parameters requires you to be mindful of how the code you’re writing behaves at deployment time, and also at synthesis time. This makes it harder to understand and reason about your AWS CDK application, in many cases for little benefit.
Generally, it’s better to have your CDK app accept necessary information in a well-defined way and use it directly to declare constructs in your CDK app. An ideal AWS CDK-generated AWS CloudFormation template is concrete, with no values remaining to be specified at deployment time.
What I’m missing, though, is the reasoning behind this, and any suggested alternatives. Sure, AWS is a proprietary service, they have the right to be opinionated, so we can’t really expect AWS to come up with a reason.
As for the alternatives, how do large organisations using CDK deploy? Do they all just trust CDK to be idempotent and generate the same template given the same parameters? CDK also encourages creating reusable constructs. Should we just trust the pinning mechanisms of our package managers to make sure of idempotency?
I feel like I’m stuck in a loop here, or maybe missing something really obvious. How to deploy with CDK without praying that nothing breaks?