How to combine boto3 and cdktf?

Is it possible to combine cdktf code and run boto3 commands after the Stack or as part of the Custom Stack? Would appreaciate for the documentation or some example.

It is possible to an extent, however, it may not be the best option.

You can run boto3 commands and use that as input to what you create in your stack, though using data sources would generally be a better option.

You can use a provisioner on certain resources which technically allow you to run any command, though this is generally not recommended as you don’t get the normal terraform guarantees.

There isn’t an api for cdktf at this time, but you could have a separate program that invokes the cli and then runs boto3 commands afterwards.

It’s also possible to write a custom provider and use that within cdktf, but that is a bigger undertaking. There was a suggestion of an easier way to do this, but it doesn’t exist at this point.

Thank you.

I solved the issue with the updating retention policy of the cloud watch log group which is implicitly created by the resource with wrapping boto3 in the separate stack and put explicit dependency on it. I don’t really like this solution.

Maybe there is an easier way to import resources into the state with the CDKTF, but I didn’t find it so far.

Often times you can explicitly create the log group and then the resource will use the existing one rather than creating its own.

There isn’t an easy way at the moment, but you can create the resource in CDKTF and then run terraform import directly.

There are many instances when datasource is not available for a resource. I’m running boto3 inside the stack and using it somewhere as a input.