I am working on AWS CDK (ver2 since we all hated the versioning in ver1) in js/ts, and I am trying to replace our current Cloudformation stack/implementation with CDK, for some obvious reasons.
The current Cfn repo has a structure like this:
.
├── cloudformation
│ ├── params
│ │ └── submit
│ │ ├── e2e.json
│ │ ├── preprod.json
│ │ └── prod.json
│ ├── stack
│ │ └── submit.yml
│ └── tags
│ ├── e2e.json
│ ├── preprod.json
│ └── prod.json
├── deploy.sh
├── ops
│ ├── add-state.sh
│ ├── create-or-update-stack.sh
│ └── upload-zendesk-templates.sh
├── state-machine
│ ├── Submit.json
│ └── SubmitSubStateMachine.json
└── zendesk-template
├── some_handlebars_zendesk_template_1.hbs
└── some_handlebars_zendesk_template_2.hbs
The Cloudformation stack is defined in the yaml file underneath ./cloudformation/stack/
. All thw parameters that are used in different environments are defined in the json file in the directory of ./cloudformation/params/{stackname}/{env}/
, that are referenced/reflected in the stack definition that looks like this (with a lot of !Sub
and !Ref
):
ZendeskWorkerLambdaArn:
Fn::ImportValue: !Sub "${ZendeskWorkerInfrastructureStackName}-ZendeskWorkerLambdaArn"
ZendeskDomain: !Ref ZendeskDomain
FooBarGroupId: !Ref FooBarGroupId
What this stack does is that:
- it kicks off once it receives an invocation signal from the backend, and;
- it subsequently invokes a lambda worker along with a template name(key) stored in an S3 bucket, and;
- it also passes params to a state machine in which the worker gets all the params and does some business logic stuff (out of scope of this Cfn question).
Note that all these handlebars template files are uploaded to an s3 bucket by running aws-cli in a shell script (under ./ops/
).
Since I am trying to use CDK to replace this very config-heavy and shell-heavy Cfn project, I came into an issue that is what I am supposed to do with all these params for different env. I've used the cdk.CfnParameter
to define environment variables in CDK stack definition. I guess I can do it again but the issues are:
- how can I differentiate the same variables (name) but under different env?
- the amount of env I have to attach to the end of the
cdk deploy
command is huge, and that makes the whole command looks tedious. (currently there are around 40 params defined in the json file for each environment) - having params at deployment time is genuinely discouraged by aws.
I have run out of ideas of how to get this issue solved. Much appreciated if anyone can give me just a little bit of ideas and also sorry for the super long post. Tho I do hope I have provided enough context (speaking of context, is CDK context something I should be looking at?)
Cheers, Adam