Given a situation where the same AWS account will host the Dev
and UAT
cloud deployments simultaneously, what is the best way to instantiate and segregate those 2 pseudo-environments?
I say "pseudo" because the cdk Environment
only takes in an account id & region. There is no other separation mechanism.
I could hand down the prefix manually into resource names by passing variables to the Construct
constructor call which is passed in by the Stack
constructor
main(args) {
app App = ...
Stack(app, "stackid", bucketPrefix = args[0])
But I’m asking if there is a cdk/aws native way that enables this instead.
Thank you in advance for your consideration and response.
2
Answers
While the CDK best practice is separate environments for Dev and UAT, it’s certainly possible to deploy multiple app copies in the same account/region pair*.
DevMyStack
andUatMyStack
. Child construct identifiers inherit their parent’s scope, so passing the prefixes down the construct hierarchy isn’t required. The docs have an example of duplicating stacks within an app, which has the same constraints as your case.* Your apps should not contain "singleton" resources that are created once per account/region.
Most constructs have a name attribute that can be assigned. CDK prefers you to leave this blank – doing so adds a random string of characters to the end of the generated name, allowing for multiple deployments in the same account-region.
This is not very human readable or easy to tell apart. Tags can help with this (tag each set with its own tag). My preference is to go ahead and use the Name fields, but programatically add a suffix
my-lambda and my-dynamodbTable become
blue-my-lambda
andblue-my-dynamodbTable
vsgreen-my-lambda
andgreen-my-dynamodbTable
just a simple variable concated string in the name attribute wil handle this, and still is mostly in line with
synth-time-decision-making
if you pass the name in from the stack constructor at the app level. This also prevents the need for multiple apps in your repo.