Is it an Anti-Pattern to get configuration details from a Dynamodb table using CDK?

Hey all,

I have a CDK app that requires some inputs to dynamically generate resources.

I don’t want these config values to exist within the app but rather they are being stored in a DDB table.

My question is, is it a bad practice to store these infrastructure config files in Dynamodb which would be fetched by the CDK deploy process?

Thanks

–There’s a service for that :https://aws.amazon.com/secrets-manager/--

Edit: too many tabs open. Please disregard.

Does work since the config values are complex structures - JSON like structures

Apologies. I had too many tabs open and got some wires crossed. Look into appconfig. https://docs.aws.amazon.com/appconfig/latest/userguide/what-is-appconfig.html

What about Parameter store :slight_smile:

No not necessary an anti pattern, there are more purpose build Services like Parameter store or secret Manager. But no body is stopping you from using dynamodb, s3 or something else.

Suggested parameter store above …

4kb max, should be sufficient for most configs.. also in contrast to secret manager or dynamo it is free :wink: (at least standard parameters are)

AppConfig, or Parameter Store would be my “maybe try this?” Recommendation but fetching them from dynamo would work, yeah

Paramter store and secret manager nativity integrated with cloudformation, CDK, so you can hide sensitive data rather than expose it in the template as a variable or hard coded.
That would be my fist choice.

Not an antipattern at all, patterns do not specify services but strategies, and storing configuration in your environment is a great idea.

Others already told you about better aws services, you cold also use Hashicorp Vault o consul.

I pull values from the parameter store into an EKS K8s pod and have JSON in some of them. For me I use ASCP which has JMESPath functionality which allows me to make a bunch of k:v pairs from the JSON structure in the parameter store.

I know not 100% related but it illustrates how great parameter store is for this kind of thing. It’s also going to be cheaper than running an DynamoDB instance.

Do you do it as part of the deployment process?

In my case I fill in the PS values as part of a CI/CD pipeline. On the EKS side I have automation that installs the security store CSI driver and ASCP providers as part of my cluster build along with updates to my IRSA role to allow reading the particular PS path. The rest is pretty easy in K8s. I have a manifest that creates the SecretProviderClass where I map the k:v’s using JMESPath. From there my deployment manifest has the volume configuration lines needed to mount the PS store objects. And what I get is a file system with files that correspond to the PS key name with contents of the value. I deploy all of this via my CI/CD deployment process.

YMMV depending on your workflow and your CI/CD platform. I do most everything in K8S. But PS works equally well for EC2 instance deployed apps etc.

For me, this document describes using PS with EKS. https://docs.aws.amazon.com/systems-manager/latest/userguide/integrating_csi_driver.html

App Config is the way to go in my opinion

Avoid fetching data in your cdk apps, we’ve found it to be troublesome. Where possible, do as folks have said here by referencing parameter store values (rather than fetching them). If that does not work, use a cloudformation custom resource to fetch your configuration at deploy time (instead of build/synth time)

CDK philosophy is to have all data in git along with the CDK code. They believe it’s best practice to be able to know exactly was was deployed by looking into just one place.

You can still achieve that with configuration in an external database by having a two step build that first fetches the configuration and generates files that must be committed in order to be deployed.

I don’t believe it’s an anti-pattern to skip all this. You may have issues if you use projen where this philosophy is enforced a bit more.

So bottom line, it’s ok. I have built a similar system for a big company and we didn’t have any issues with that. Our data was saved in RDS and was used to generate whole environments. See here for more details https://kichik.com/2022/01/10/implementing-automatic-safe-hands-off-deployment-in-aws/

It’s an anti-pattern (even though I hate that term).

The whole purpose of Infrastructure-as-Code is to be able to make the process repeatable and to control changes to infrastructure. When you start adding configuration that isn’t in version control, you are undermining the whole purpose of using IaC.

Why can’t your config files be stored in source control with your CDK code?

Your code can generate configs that are consumed by your applications, but you shouldn’t have configuration that drives creation of resources sitting outside of source control.

That’s not what the question is about. The question is about dynamic creation of resources based on stuff stored in DynamoDB.

That is definitely antithetical to IaC and CDK.

Dynamodb is an anti pattern.

We might not be a good example but we base64 encode complex structures into strings we can store via param store / secrets manager. But there’s not an intrinsic CF decode function.